My XML has 100 AgentSales nodes I only want to show the first 10 so far I have
<xsl:for-each select="NewDataSet/AgentSales">
<tr>
<xsl:if test="(position() mod 2 = 1)">
<xsl:attribute name="bgcolor">#cccccc</xsl:attribute>
</xsl:if>
<td>
<span style="font:20px arial; font-weight:bold;">
<xsl:value-of select="AgentName"/>
</span>
</td>
<td>
<span style="font:20px arial; font-weight:bold;">
<xsl:value-of select="State"/>
</span>
</td>
<td>
<span style="font:20px arial; font-weight:bold;">
<xsl:value-of select="time"/>
</span>
</td>
</tr>
</xsl:for-each>
New to the site but when I use the code brackets not all of my code shows? at least not in the preview below.
You create an XSLT loop with the <xsl:for-each> tag. The value of the select attribute in this tag is an XPath expression that allows you to specify the data element to loop through. XPath expressions are constructed like file paths in an operating system, the forward slash (/) selects subdirectories.
The <xsl:for-each> element selects a set of nodes and processes each of them in the same way. It is often used to iterate through a set of nodes or to change the current node. If one or more <xsl:sort> elements appear as the children of this element, sorting occurs before processing.
Specifies the format pattern. Here are some of the characters used in the formatting pattern: 0 (Digit) # (Digit, zero shows as absent)
The <xsl:for-each> element establishes the context for iteration. The XSLT transformation instructions within this loop are to be applied to the selected nodes.
Use:
<xsl:for-each select="NewDataSet/AgentSales[not(position() >10)]">
<!-- Process each node from the node-list -->
</xsl:for-each>
Even better:
<xsl:apply-templates select="NewDataSet/AgentSales[not(position() >10)]"/>
Try something like:
<xsl:for-each select="NewDataSet/AgentSales">
<xsl:if test="position() <= 10">
...
</xsl:if>
</xsl:for-each>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With