xsl-list
[Top] [All Lists]

[xsl] loop elements based on attribute

2008-08-13 00:18:50
Hi! 

I've got this source-XML: 

<test>
<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>
<Pkt type="pkt">Lot of text</Pkt>
<Pkt type="pkt">Tons of text</Pkt>
<Pkt type="uavs">Tons of text 1</Pkt>
</test> 

When I reach a Pkt-element which does NOT have attribute type='uavs' I should 
check if the next Pkt-sibling has attribute type='uavs'. 

If so, I want to loop through all the Pkt-elements with attribute type='uavs' 
that appears right after the current element. 

When a new Pkt-element without the 'uavs' attribute value appears, the loop is 
fininshed. 

I've tried something like this, but that only lists all the elements with 
uavs-attribute one time: 

<xsl:if test="following-sibling::Pkt[1][(_at_)type='uavs'] ">
<xsl:for-each select="following-sibling::Pkt[(_at_)type='uavs']
[preceding-sibling::*[1][self::Pkt]][generate-id(preceding-sibling::Pkt[not(preceding-sibling::*[1][self::Pkt])][1])
 = generate-id(current())]">
<A><xsl:value-of select="."/></A>
 </xsl:for-each>
</xsl:if> 

My result-XML should look like this: 

<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>
<Pkt>
            <A>Lot of text</A>
</Pkt>
<Pkt>
            <A>Tons of text</A>
            <A>Tons of text 1</A>
</Pkt> 

I use xsl 2.0.

Thanx!!

Kjellaug.

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