descendant::tag name : descendant « XSLT stylesheet « XML






descendant::tag name


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>

 








Related examples in the same category

1.descendant demo
2.select="descendant::title[last()]"
3.select="descendant::figure/title[last()]"
4.value-of select="descendant::lastName"