-1

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

<users xmlns="ABC_Login">
   <email>ABC@gmail.com</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"?>
   ABC@gmail.com

Expected Output is:

    <?xml version="1.0" encoding="UTF-8"?>
<users>       
<email>ABC@gmail.com</email>
</users>

Can anybody help me?

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

user3141034
  • 161
  • 3
  • 5
  • 15

2 Answers2

1

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>
Waqas Ali Razzaq
  • 659
  • 1
  • 5
  • 30
0

You had the right idea. You declared the namespace you need in your XSLT, but you're not using it. This should do it:

<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">
    <users>               
      <email><xsl:value-of select="users:email"/></email>
    </users>
  </xsl:template>
</xsl:stylesheet>

Of course, this just makes an exact copy of the input, and there are better ways to do that, but I assume you're just doing this for practice.

JLRishe
  • 99,490
  • 19
  • 131
  • 169