xsl-list
[Top] [All Lists]

RE: predicate inside a for-each

2006-01-01 10:44:25
Do

<xsl:for-each select="head/row">
  <xsl:variable name="ROWPOSITION" select="position()"/>

then subsequently use $ROWPOSITION

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: yaXay [mailto:yaXay(_at_)gmx(_dot_)net] 
Sent: 01 January 2006 15:51
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] predicate inside a for-each

Hi,

imagine the following scenario:

XML:
<table>
    <head>
        <row>row 1</row>
        <row>row 2</row>
    </head>
    <body>
        <field>field 1</field>
        <field>field 2</field>
        <field>field 3</field>
        <field>field 4</field>
    </body>
</table>

I would like to generate a XHTML table looking (a bit) like this:
row 1        field 1      field3
row 2        field 2      field4

However, I ran into a brick wall:
<xsl:template match="table">
    <table>
        <xsl:for-each select="head/row">
            <tr>
                <td><strong><xsl:value-of select="."/></strong></td>
                <xsl:for-each select="../../body/field[position() mod 
count(../../head/row) = ROWPOSITION]">
                    <td><xsl:value-of 
select="position()"/>-<xsl:value-of select="../../@row-count"/></td>
                </xsl:for-each>
            </tr>
        </xsl:for-each>
    </table>
</xsl:template>

ROWPOSITION needs to be the position of the row, which is 
processed by 
the outer for-each. However, I can't think of any XPath expression to 
get there..
Of course I could call another template and pass the row 
position as a 
parameter, but I'd like to avoid that..

Any suggestions??

Thanks,
Ben


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>