Reputation: 351
With the following xml document
<?xml version="1.0" encoding="UTF-8"?>
<a name="john">
<b/>
</a>
and the following 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="a">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
The output is
<?xml version="1.0" encoding="UTF-8"?><a/>
What i want is <a name="John"/>
. How do i get the element a
along with its attribute name
and without its child b
?
Upvotes: 1
Views: 639
Reputation: 167716
Copy the attributes as well:
<xsl:template match="a">
<xsl:copy>
<xsl:copy-of select="@*"/>
</xsl:copy>
</xsl:template>
Upvotes: 3