xsl-list
[Top] [All Lists]

RE: [xsl] RE: xsl for

2006-04-07 08:25:27

<pageBrowser startPage="5" pageSize="10"/>

And I want this output :

<a href="toto.htm?skip=50">5</a>
<a href="toto.htm?skip=60">6</a>
<a href="toto.htm?skip=70">7</a>
<a href="toto.htm?skip=80">8</a>
<a href="toto.htm?skip=90">9</a>
<a href="toto.htm?skip=100">10</a>
<a href="toto.htm?skip=110">11</a>
<a href="toto.htm?skip=120">12</a>
<a href="toto.htm?skip=130">13</a>
<a href="toto.htm?skip=140">14</a>

Not sure here whether 10 is the number of <a> elements to generate or the
multiplier. I'll use it for both...

In XSLT 2.0, it's easy (as things often are!)

<xsl:for-each select="@startPage to (@startPage + @pageSize - 1)">
  <a href="tot.htm?skip={10*.}"><xsl:value-of select="."/></a>
</xsl:for-each>

(You might have to cast the attribute values to xs:integer if your source
document doesn't have a schema)

In 1.0 you use the Piez trick of iterating over a sufficiently large but
otherwise arbitrary node-set:

<xsl:for-each select="//node()[position() &lt= $pageSize]">
  <a href="tot.htm?skip={10*(position()-1+$startPage}"><xsl:value-of
select="position()-1+$startPage"/></a>
</xsl:for-each>

having first initialized the two variables.

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


I mean I want to use a loop somewhere and I don't want to have 

<xsl:template match="pageBrower">
      <a href="toto(_dot_)htm?skip={(_at_)startPage*@pageSize}"><xsl:value-of
select="@startPage"/></a>
      <a href="toto.htm?skip={(@startPage+1)*(_at_)pageSize}"><xsl:value-of
select="@startPage+1"/></a>
      <a href="toto.htm?skip={(@startPage+2)*(_at_)pageSize}"><xsl:value-of
select="@startPage+2"/></a>
      <a href="toto.htm?skip={(@startPage+3)*(_at_)pageSize}"><xsl:value-of
select="@startPage+3"/></a>
      ...
</xsl:template>

Thanks in advance

Philippe



--~------------------------------------------------------------------
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>