XML : Count nodes matching string pattern in XML

How do I count the number of times the words LIST, BUY or SELL are in the chart_name node of this XML document? I am trying to figure out how many times each are listed in that node from the parent node test_name.

  <?xml version="1.0" encoding="utf-8"?>  <digital1>    <test_name ID="Test">      <record>        <chart_name>LIST OR BUY Test 1</chart_name>      </record>      <record>        <chart_name>LIST Test 2</chart_name>      </record>    </test_name>    <test_name ID="Ryan">      <record>        <chart_name>BUY Ryan 1</chart_name>      </record>      <record>        <chart_name>LIST Ryan 2</chart_name>      </record>      <record>        <chart_name>SELL OR LIST Ryan 3</chart_name>      </record>      <record>        <chart_name>LIST OR BUY Ryan 4</chart_name>      </record>      <record>        <chart_name>BUY Ryan 5</chart_name>      </record>      <record>        <chart_name>LIST Ryan 6</chart_name>      </record>    </test_name>  </digital_tpp>    

The XSLT file I am using looks like this:

  <xsl:template match="/">    <html>    <body>    <h2>My Test File</h2>        <xsl:for-each select="digital1/test_name/record]">          <tr>            <td><xsl:value-of select="../@ID"/></td>            <td><xsl:value-of select="count(chart_name[. Like '*LIST*'])"/></td>          </tr>        </xsl:for-each>      </table>    </body>    </html>  </xsl:template>    

It is this line <td><xsl:value-of select="count(chart_name[. Like '*LIST*'])"/></td> I am needing help with. How do I do a pattern match to match those key words above?

The output will be a table showing test_name ID, count of LIST, count of BUY and count of SELL.

No comments:

Post a Comment