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

Re: RE: loop elements based on attribute

Subject: Re: RE: loop elements based on attribute
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Sat, 16 Aug 2008 16:10:35 +0200
Re:  RE: loop elements based on attribute
Mukul Gandhi wrote:

<xsl:for-each-group select="*" group-adjacent="self::Pkt">

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


1) Why do we get error [1] in the 1st case ?

Well the error message explains that, an empty sequence is not allowed as the grouping key for group-adjacent and your expression self::Pkt evaluates to an empty sequence for the 'A' and 'B' elements in the input XML.


2) In the second case, why putting the expression in 'boolean'
function works, while without boolean, we get an error ?

Now, using group-adjacent="boolean(self:Pkt)" the grouping key for the 'Pkt' elements is the boolean value true and for the other elements (i.e. the 'A' and 'B' elements) it is the boolean value false (as boolean(self:Pkt) is boolean() applied to an empty sequence which yields false).



> And, why do
we get 4 groups, and not 2 ?

See the definition for group-adjacent:


"the items in the population are examined, in population order. If an item has the same value for the grouping key as its preceding item within the population (in population order), then it is assigned to the same group as its preceding item; otherwise a new group is created and the item becomes its first member"

So the 'A' element which has the grouping key false becomes a member of the first group, then the 'Pkt' element following that becomes a member of the second group, all 'Pkt' elements following that also become a member of the second group, then the 'B' and 'A' element become a member of the third group, and finally the 'Pkt' elements become members of the fourth group.

If you only want to group the 'Pkt' elements then you could use e.g.
<xsl:if test="current-grouping-key()">
<List>
<xsl:copy-of select="current-group()"/>
</List>
</xsl:if>
as only for the 'Pkt' elements the group-adjacent="boolean(self::Pkt)" gives true.


--

	Martin Honnen
	http://JavaScript.FAQTs.com/

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.