Subject: Re: [xsl] RE: loop elements based on attribute From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Sat, 16 Aug 2008 18:02:06 +0530 |
I am using Saxon 9.1.0.1J (basic, version) I used this XML, <?xml version="1.0" encoding="UTF-8"?> <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> This stylesheet, <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="test"> <test> <xsl:for-each-group select="*" group-adjacent="self::Pkt"> <List> <xsl:copy-of select="current-group()" /> </List> </xsl:for-each-group> </test> </xsl:template> </xsl:stylesheet> produces following error [1], Error on line 8 of test.xsl: XTTE1100: An empty sequence is not allowed as the @group-adjacent attribute of xsl:for-each-group in built-in template rule Transformation failed: Run-time errors were reported While this stylesheet, <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="test"> <test> <xsl:for-each-group select="*" group-adjacent="boolean(self::Pkt)"> <List> <xsl:copy-of select="current-group()" /> </List> </xsl:for-each-group> </test> </xsl:template> </xsl:stylesheet> (please note the 'boolean' function I have used now) produces output [2], <?xml version="1.0" encoding="UTF-8"?> <test> <List> <A>test</A> </List> <List> <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> </List> <List> <B>test</B> <A>test</A> </List> <List> <Pkt type="num">Lot of text</Pkt> <Pkt type="num">Tons of text</Pkt> <Pkt type="uavs">Tons of text 1</Pkt> </List> </test> My questions are, 1) Why do we get error [1] in the 1st case ? 2) In the second case, why putting the expression in 'boolean' function works, while without boolean, we get an error ? And, why do we get 4 groups, and not 2 ? I was expecting following output in the 2nd case (although, I expected the 1st stylesheet to have worked as well) ... <?xml version="1.0" encoding="UTF-8"?> <test> <List> <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> </List> <List> <Pkt type="num">Lot of text</Pkt> <Pkt type="num">Tons of text</Pkt> <Pkt type="uavs">Tons of text 1</Pkt> </List> </test> -- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] RE: loop elements based o, Martin Honnen | Thread | Re: [xsl] RE: loop elements based o, Martin Honnen |
Re: [xsl] nbsp and copy-of and outp, Dave Pawson | Date | Re: [xsl] RE: loop elements based o, Martin Honnen |
Month |