Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] predicate inside a for-each

From: "Michael Kay" <mike@------------>
To:
Date: 1/1/2006 5:45:00 PM
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: [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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent