p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Finding the 10th row in a xsl (http://p2p.wrox.com/showthread.php?t=54045)

SOMANATHAN10 February 14th, 2007 06:32 AM

Finding the 10th row in a xsl
 
I am not able to use the position function and predicate the if
condition along with for-each does not work for me.

    <xsl:for-each select="catalog/cd">
     <xsl:if some condition>
     For every 10th time I need to call a template.
   How to identify the every 10th row???


C.SOMA

bonekrusher February 16th, 2007 08:16 AM

Sometime I use a variable & MOD:

Code:



<xsl:for-each select="catalog/cd">
<xsl:variable name="pos" select="position()"/>
     <xsl:if $pos mod 10 = 1>
.......

This is not tested. let me know how it works out.

mhkay February 16th, 2007 08:35 AM

Is this supposed to be a question, or is it some random musings? If you want people to spend time helping you, please say clearly what you are trying to achieve and where your difficulty lies.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

SOMANATHAN10 February 19th, 2007 12:22 AM

Mich,

This is my question:I am trying to call header template when an if condition is satisfied. See the following lines in the code snippet.
I am not able to call the header template as the position value is frequently changing.Anyhow I want to identify the every 10th row.This is my requirement.
<xsl:if test position() mod 10 = 1>
<xsl:call-template name="header">
</xsl:if>

code snippet:
===========

 <xsl:for-each select="/job/summary/sunAlertReport/rs:sunAlertReportSummary/rs:sunAlertSummaryList/rs:sunAlertSummary/rs:sunAlertId[generate-id()=generate-id(key(&apos;distinct-segcode&apos;,.))]">
                                    <xsl:sort order="ascending" select="."/>
                                    <xsl:variable name="SA" select="."/>
                                    <xsl:if test="count(/job/summary/sunAlertReport/rs:sunAlertReportSummary/rs:sunAlertSummaryList/rs:sunAlertSummary[rs:sunAlertId=$SA]/rs:oriNext/rs:oriNextList/rs:oriRule[rs:severity = 'Critical']) &gt; 0">
                                    <xsl:if test position() mod 10 = 1>
                                    <xsl:call-template name="header">
                                    </xsl:if>
                                    <xsl:call-template name="saItem">
                                    <xsl:with-param name="hostCount" select="$hostCount"/>
                                    <xsl:with-param name="severity">Critical</xsl:with-param>
                                    </xsl:call-template>
                                    </xsl:if>
                                </xsl:for-each>

C.SOMA

mhkay February 19th, 2007 04:39 AM

Looks like a tough one to crack with XSLT 1.0. Can you use 2.0?

Please try to describe your *requirements", that is, the input and output of the transformation, not the code you are trying to write to solve the requirement. Then we could consider alternative approaches.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference


All times are GMT -4. The time now is 04:51 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.