Search code examples
xmlxsltxslt-1.0xslt-2.0xslt-grouping

unable to add element in xml using xslt


I am new to xslt. I have a small xml code snippet as below.

<users xmlns="ABC_Login">
   <email>[email protected]</email>
</users>

And I have xslt code is below.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:users= "ABC_Login"
xmlns= "ABC_Login" >
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
    <xsl:template match="//users">
<users>               
<email><xsl:value-of select="email"/></email>
</users>
</xsl:template>
</xsl:stylesheet>

Current output is:

<?xml version="1.0" encoding="UTF-8"?>
   [email protected]

Expected Output is:

    <?xml version="1.0" encoding="UTF-8"?>
<users>       
<email>[email protected]</email>
</users>

Can anybody help me?

Note:I am using online xslt validator http://xslttest.appspot.com/


Solution

  • Please try this solution. I have check it with XmlSpy. May be your online tool is not working fine.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="ABC_Login" exclude-result-prefixes="ns1" version="1.0">
        <xsl:template match="/ns1:users">
            <users>
                <email>
                    <xsl:value-of select="ns1:email" />
                </email>
            </users>
        </xsl:template>
    </xsl:stylesheet>