Mega Code Archive

 
Categories / XML / XSLT StyleSheet
 

Child

File: Data.xml <wine grape="A">   <winery>B</winery>   <year>1998</year>   <prices>     <list>13.99</list>     <discounted>11.99</discounted>     <case>143.50</case>   </prices> </wine> File: Transform.xslt <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   version="1.0">   <xsl:template match="wine">     <wine vintage="{child::year}">       <xsl:apply-templates select="product" />       <category>         <xsl:value-of select="@grape" />       </category>       <xsl:apply-templates select="price" />     </wine>   </xsl:template>   <xsl:template     match="@*|node()|processing-instruction()|comment()">     <xsl:copy>       <xsl:apply-templates         select="@*|node()|processing-instruction()|comment()" />     </xsl:copy>   </xsl:template> </xsl:stylesheet> Output: <?xml version="1.0" encoding="UTF-8"?><wine vintage="1998"><category>A</category></wine>