template match="para[contains(.,'the')]" : contains « XSLT stylesheet « XML






template match="para[contains(.,'the')]"


File: Data.xml
<story>

  <chapter>
    <title>Chapter 1</title>
    <para>para 1</para>
  </chapter>

  <chapter>
    <title>Chapter 2</title>
    <para>item 1</para>
    <para>item 2</para>
    <sect>
      <title>Chapter 2, Section 1</title>
      <para>item 3</para>
      <para>para 2</para>
    </sect>
  </chapter>

  <chapter>
    <title>Chapter 3</title>
    <para>para A</para>
  </chapter>

</story>


File: Transform.xslt

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="text" />

  <xsl:template match="para[contains(.,'the')]">
    *** This para has "the" in it: ***
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="para">
    *** This para element not processed by other template: ***
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="title" />
</xsl:stylesheet>

Output:



  
    
    
    *** This para element not processed by other template: ***
    para 1
  

  
    
    
    *** This para element not processed by other template: ***
    item 1
    
    *** This para element not processed by other template: ***
    item 2
    
      
      
    *** This para element not processed by other template: ***
    item 3
      
    *** This para element not processed by other template: ***
    para 2
    
  

  
    
    
    *** This para element not processed by other template: ***
    para A
  

 








Related examples in the same category

1.contains function
2.match element with certain value