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

RE: Looping in XSLT(old question, but maybe new proble

Subject: RE: Looping in XSLT(old question, but maybe new problem)
From: "Liu Shuai" <shuai@xxxxxxxxxxxxxxxxx>
Date: Tue, 24 Jun 2003 00:16:35 -0400
xslt foreach following sibling current
Mike,

Thank you for your response. I got another issue,though.

I have the template like this:
<xsl:template match="foo">
	<table>
      	<xsl:for-each select="bar">
		<xsl:sort select="@id" data-type="number"/>
            <xsl:if test="(number(position()) mod 3) = 1">
			<tr>
                  	<td>
                        	<xsl:value-of disable-output-escaping="yes"
select="someElement"/>
	                  </td>
				<td>
					<xsl:for-each select="following-sibling::bar[position()=1]">
						<xsl:value-of disable-output-escaping="yes" select="someElement"/>
					</xsl:for-each>
				</td>
				<td>
					<xsl:for-each select="following-sibling::bar[position()=2]">
						<xsl:value-of disable-output-escaping="yes" select="someElement"/>
					</xsl:for-each>
				</td>
			</tr>
		</xsl:if>
		</xsl:for-each>
	</table>
</xsl:template>

As you see, I sorted bar based on some rule in for-each. When I get the next
two element, how can I keep
the order? Looks to me following-sibling fetch elements based on the orginal
order in the source
file.

Thank you.
LS

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Mike Brown
Sent: Monday, June 23, 2003 10:04 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Looping in XSLT(old question, but maybe new problem)


Liu Shuai wrote:
> 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>&nbsp;</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.

Select all bar elements for processing.
In the template that matches a bar element, if position() returns
a value that when divided by 3 has a remainder of 1, generate a table row
element. Inside that element, create cells for the current node and its
first two following siblings.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.