Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsl, xml, counting valid records

Status
Not open for further replies.

YYYYUU

Programmer
Dec 13, 2002
47
GB
My xml is as follows:
<BALANCES>
<data>
<recno>1</recno>
<CLASS>
<TYPE>C</TYPE>
<CODE>70</CODE>
<DESCRIPTION>UNKNOWN</DESCRIPTION>
<ISIN/>
<BALANCE>1066.0000</BALANCE>
<REGNDATE>25-FEB-2003</REGNDATE>
<PUBLICVIEW>Y</PUBLICVIEW>
</CLASS>
</data>
<data>
<recno>2</recno>
<CLASS>
<TYPE>C</TYPE>
<CODE>73</CODE>
<DESCRIPTION>CSPSBAL28JAN</DESCRIPTION>
<ISIN/>
<BALANCE>1066</BALANCE>
<REGNDATE>17-MAR-2003</REGNDATE>
<PUBLICVIEW>N</PUBLICVIEW>
</CLASS>
</data>
<data>
<recno>3</recno>
<CLASS>
<TYPE>C</TYPE>
<CODE>74</CODE>
<DESCRIPTION>UNKNOWN</DESCRIPTION>
<ISIN/>
<BALANCE>1066.0000</BALANCE>
<REGNDATE>13-JAN-2003</REGNDATE>
<PUBLICVIEW>Y</PUBLICVIEW>
</CLASS>
</data>
..etc...

I want to display only the first two BALANCES (in order of recno), where the PUBLICVIEW is Y. There can be several records. This xml is used for other things so I don't want to change the actual xml.


<xsl:apply-templates select="BALANCES/data[CLASS/PUBLICVIEW='Y']"/>

<xsl:template match="BALANCES/data">
<tr>
<td width="25%" valign="top" class="small" align="right">
<b>
<xsl:value-of select="CLASS/BALANCE"/>
</b>
</td>
<td width="2%"/>
<td width="4%" valign="top" class="small">in</td>
<td width="69%" valign="top" class="small">
<xsl:value-of select="CLASS/DESCRIPTION"/>
</td>
</tr>
</xsl:template>


Can I add a counter to the template, to only go through everything twice? I know xsl:variable exists but I understood this was more of a constant, and couldn't be changed or incremented.

You help is much appreciated.
 
I've managed to solve my problem.


<xsl:template match="BALANCES/data">
<xsl:variable name="counter">
<xsl:value-of select="position()"/>
</xsl:variable>
<xsl:if test="$counter&lt;=2">
<tr>
<td width="25%" valign="top" class="small" align="right">
<b>
<xsl:value-of select="CLASS/BALANCE"/>
</b>
</td>
<td width="2%"/>
<td width="4%" valign="top" class="small">in</td>
<td width="69%" valign="top" class="small">
<xsl:value-of select="CLASS/DESCRIPTION"/>
</td>
</tr>
</xsl:if>
</xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top