[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: predicate inside a for-each

Subject: RE: predicate inside a for-each
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 1 Jan 2006 17:44:25 -0000
RE:  predicate inside a for-each
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@xxxxxxx] 
> Sent: 01 January 2006 15:51
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.