I need to modify a XML using XSLT 1.0. Basically, I need to copy the attribute (name and value) to one child.
This is the xml:
<parent id="3450">
<son1>
<name>Malcom</name>
<age>15</age>
<description>This is the middle son</description>
</son1>
<son2>
<name>Francis</name>
<age>19</age>
<description>This is the oldest son</description>
</son2>
<son3>
<name>Dewey</name>
<age>9</age>
<description>This is the youngest son</description>
</son3>
</parent>
This should be the result:
<parent id="3450">
<son1 id="3450">
<name>Malcom</name>
<age>15</age>
<description>This is the middle son</description>
</son1>
</parent>
This is the XSLT that I’m working with:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="parent/son1">
<xsl:copy>
<xsl:attribute name="id"><xsl:value-of select="../@id"/></xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="parent/son2" />
<xsl:template match="parent/son3" />
The XSLT seems to be working, but my question is: Is this the right way to do it?
Thanks.
I would change
to