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

RE: loop elements based on attribute

Subject: RE: loop elements based on attribute
From: "Kjellaug Johansen" <kjellaug.johansen@xxxxx>
Date: Fri, 15 Aug 2008 16:42:28 +0200
 RE: loop elements based on attribute
Hi.

My problem just turned to be a bit bigger.

In an xslt-file I use templates for each match on different elements.
When I reach a Pkt-element I call the template "pktTemplate". How can I
get the right result? I'm almost there...but the problem is that the
first Pkt-element that matches (where the template-call is done) is
never listed in the result. But the siblings are listed at the right
way.

My source XML:
<test>
	<A>test</A>
 	<Pkt type="pkt">Text</Pkt>
 	<Pkt type="uavs">Text 1</Pkt>
 	<Pkt type="pkt">More text</Pkt>
 	<Pkt type="uavs">More text 1</Pkt>
 	<Pkt type="uavs">More text 2</Pkt>
 	<B>test</B>
 	<A>test</A>
	<Pkt type="num">Lot of text</Pkt>
	<Pkt type="num">Tons of text</Pkt>
	<Pkt type="uavs">Tons of text 1</Pkt>
 </test>

My result today (which is wrong):
<List>
	<Pkt>
		<A>Text 1</A>
	</Pkt>
	<Pkt>
		<A>More text</A>
		<A>More text 1</A>
		<A>More text 2</A>
	</Pkt>
</List>
<List>
	<Pkt>
		<A>Tons of text</A>
		<A>Tons of text 1</A>
	</Pkt>
</List>

The result I want (the right one):
<List>
	<Pkt>
		<A>Text</A>
		<A>Text 1</A>
	</Pkt>
	<Pkt>
		<A>More text</A>
		<A>More text 1</A>
		<A>More text 2</A>
	</Pkt>
</List>
<List>
	<Pkt>
		<A>Lot of text</A>
	</Pkt>
	<Pkt>
		<A>Tons of text</A>
		<A>Tons of text 1</A>
	</Pkt>
</List>

My xsl: (I use xsl 2.0)

//some tests on different elements, when I match a Pkt I do the
following:
<xsl:call-template name="pktTemplate"/>
<xsl:template name="pktTemplate">
	<xsl:if test="not(preceding-sibling::*[1][self::Pkt])">
		<List>
			<xsl:for-each-group
select="following-sibling::Pkt
			 [preceding-sibling::*[1][self::Pkt]][generate-
id(preceding-sibling::Pkt[not(preceding-
sibling::*[1][self::Pkt])][1])= generate-
id(current())]" group-starting-with="Pkt[not(@type =
'uavs')]">
				<Pkt>

					<xsl:for-each
select="current-group()">
						<A><xsl:value-of
select="." /></A>
					</xsl:for-each>
				</Pkt>
			</xsl:for-each-group>
		</List>
	</xsl:if>
</xsl:template>

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.