I want to convert the following xml using xslt. Note: I am using name spave in input xml
Input XML
<?xml version="1.0" encoding="UTF-8"?>
<Roottag xmlns="aaa">
<Employee>
<name>Nimal</name>
</Employee>
<Employee>
<name>Kamal</name>
</Employee>
<Employee>
<name>Sunil</name>
</Employee>
</Roottag>
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="//name">
<xsl:element name="person">
<xsl:value-of select="." />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Expected output
<?xml version="1.0" encoding="UTF-8"?>
<person>Nimal</person>
<person>Kamal</person>
<person>Sunil</person>
Current output
<?xml version="1.0" encoding="UTF-8"?>
Nimal
Kamal
Sunil
Can any one please help me to solve this name space issue in xslt2.0 transformation?
With XSLT 2.0 and an XSLT 2.0 processor you can use
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="aaa">
<xsl:template match="name">
<person>
<xsl:value-of select="." />
</person>
</xsl:template>
</xsl:stylesheet>
With an XSLT 1.0 processor you need
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:df="aaa" exclude-result-prefixes="aaa">
<xsl:template match="df:name">
<person>
<xsl:value-of select="." />
</person>
</xsl:template>
</xsl:stylesheet>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.