[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|