Thank you Jeff, that was indeed very quick response.
Just one question, if foo-bar-temp is a global variable, is the nodeset
initialized
only once or is it generated every time foo-bar-temp is called?
Regards,
LS
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of
Jeff Beadle
Sent: Tuesday, June 24, 2003 9:40 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Looping in XSLT(old question, but maybe new problem)
Hey Liu,
Just replace the xsl:variable[(_at_)name='foo-bar'] definition with this:
<!-- temp table ... er, excuse me ... I mean, temp node list -->
<xsl:variable name="foo-bar-temp">
<xsl:for-each select="foo/bar">
<xsl:sort select="@id" data-type="number"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>
<!--
Now, construct the foo-bar node list from the sorted temp list;
Doing this instead of rolling the for-each directly within the foo-bar will
prevent you from
having to use your parsers node-set/node-list adapter function to turn the
RTF into a node list.
-->
<xsl:variable name="foo-bar" select="msxsl:node-set($foo-bar-temp)/bar"/>
Sorry, for the delay ... just logged into my mail server.
-Jeff
-----Original Message-----
From: Liu Shuai [mailto:shuai(_at_)objectwareinc(_dot_)com]
Sent: Tuesday, June 24, 2003 12:52 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Looping in XSLT(old question, but maybe new problem)
Jeff,
Thank you for your response.
One concern, though. If I sort foo/bar, will foo/bar[position()] return
nodes based in my sorted order
or original order in the source file? I used following-sibling in a template
I wrote and it return nodes
in the orginal order.
Thanks!
LS
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of
Jeff Beadle
Sent: Tuesday, June 24, 2003 12:12 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Looping in XSLT(old question, but maybe new problem)
Hey Liu,
Fun one! I had one of those rare moments where I actually had a bit of time
to work on one of the problems/questions raised on this list.
Also, please be advised ... other members on this list--the experts--will
most likely provide direction and/or solutions well beyond what I'm
providing, so you may want to wait a bit to see what they contribute.
But hey, this works!
<xsl:param name="N" select="5"/>
<xsl:template match="/">
<table>
<xsl:variable name="foo-bar" select="foo/bar"/>
<xsl:variable name="foo-bar-cnt" select="count($foo-bar)"/>
<xsl:for-each select="$foo-bar">
<xsl:variable name="pos" select="position()"/>
<!-- if at the Nth column, then create a new row -->
<xsl:if test="not(($pos - 1) mod $N)">
<tr>
<!-- grab the splice ... all bars that are within the range
[$pos,$pos+$N] -->
<xsl:for-each select="$foo-bar[position()>=$pos and
position()<($pos + $N)]">
<td><xsl:value-of select="someElement"/></td>
</xsl:for-each>
<!-- if within the last row, construct enough empty cells to
"square" the table -->
<xsl:if test="$foo-bar-cnt mod $N > $foo-bar-cnt - $pos">
<xsl:for-each select="$foo-bar[position() >= 1 and
position()<=($N - ($foo-bar-cnt mod $N))]">
<td> </td>
</xsl:for-each>
</xsl:if>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</xsl:template>
Anyhow, it was fun.
-Jeff
-----Original Message-----
From: Liu Shuai [mailto:shuai(_at_)objectwareinc(_dot_)com]
Sent: Monday, June 23, 2003 8:32 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Looping in XSLT(old question, but maybe new problem)
Hi, all
I am trying to write a template that will generate a table based on a xml
file and right now I don't have any
clue how to do it.
If I have a source file looks like this
<foo>
<bar id='1'>
<someElement>a</someElement>
</bar>
<bar id='2'>
<someElement>b</someElement>
</bar>
<bar id='3'>
<someElement>c</someElement>
</bar>
<bar id='4'>
<someElement>d</someElement>
</bar>
<bar id='5'>
<someElement>e</someElement>
</bar>
...
</foo>
Can I write a style sheet that will transform the source file above to a
html table like this?
<table>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>d</td>
<td>e</td>
<td> </td>
</tr>
...
</table>
Basicly, I want to generate N columns per row but I don't know how many
"bar"s I have in the source file.
Any hint or suggestion will be greatly appreciated.
Shuai
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list