Reputation: 163
I want to get the count of elements that after the 3rd comma and not 0
in XSLT. This means I want count of <td>
between <td>MKTDATQ - NZX Equity Price Summary</td>
and <td>MKTDATQ - NZX Debt Price Summary</td>
Input:
<table>
<tr>
<td>ABC, 2, 2, 4, 10</td>
</tr>
<tr>
<td>MKTDATQ - NZX Equity Price Summary</td>
</tr>
<tr>
<td>HGT, 1, 2, 0, 4</td>
</tr>
<tr>
<td>ABC, 2, 2, 3, 10</td>
</tr>
<tr>
<td>VSD, , 4, 0, 9</td>
</tr>
<tr>
<td>MKTDATQ - NZX Debt Price Summary</td>
</tr>
<tr>
<td>KJD, 0, 9, 0, 11</td>
</tr>
</tablr>
Output should be:
<root>
<num>1</num>
</root>
Tried code:
<xsl:template name="NZX_Overview">
<xsl:if test="table/tr/td[preceding::td[starts-with(text(),'MKTDATQ - NZX Equity Price Summary')]][following::td[starts-with(text(),'MKTDATQ - NZX Debt Price Summary')]]">
<xsl:variable name="fields" select="count(table/tr/td[preceding::td[starts-with(text(),'MKTDATQ - NZX Equity Price Summary')]][following::td[starts-with(text(),'MKTDATQ - NZX Debt Price Summary')]][tokenize(text(), ',')[4] != ' 0'])" />
<root><num>xsl:value-of select="$fields"/></num></root>
</xsl:if>
</xsl:template>
The output i am getting:
<root>
<num>3</num>
</root>
I am getting output is not correct. the correct output value is 1
.
I am using XSLT 2.0
Upvotes: 0
Views: 56
Reputation: 116959
Try:
<xsl:value-of select="count(table/tr/td[preceding::td[starts-with(., 'MKTDATQ - NZX Equity Price Summary')] and following::td[starts-with(., 'MKTDATQ - NZX Debt Price Summary')] and tokenize(., ', ')[4] != '0'])" />
Not sure why you need the starts-with
part.
Upvotes: 1