Mega Code Archive

 
Categories / XML / XSLT StyleSheet
 

Descendant

File: Data.xml <chapter>   <para>para1</para>   <figure>     <title>title 1</title>     <graphic fileref="pic1.jpg" />   </figure> </chapter> File: Transform.xslt <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   version="1.0">   <xsl:output method="xml" omit-xml-declaration="yes" indent="no" />      <xsl:template match="chapter">     <chapter>       Pictures:       <xsl:for-each select="descendant::figure">         <xsl:value-of select="title" />         <xsl:text/>       </xsl:for-each>       <xsl:apply-templates />     </chapter>   </xsl:template>   <xsl:template match="@*|node()">     <xsl:copy>       <xsl:apply-templates select="@*|node()" />     </xsl:copy>   </xsl:template> </xsl:stylesheet> Output: <chapter>       Pictures:       title 1   <para>para1</para>   <figure>     <title>title 1</title>     <graphic fileref="pic1.jpg"/>   </figure> </chapter>