[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: RE: loop elements based on attribute
Mukul Gandhi wrote:
<xsl:for-each-group select="*" group-adjacent="self::Pkt"> produces following error [1], 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' 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/
|
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
|