Subject: Re: [xsl] xsl:for-each-group: start groups depending on number of group members? From: Yves Forkl <Y.Forkl@xxxxxx> Date: Mon, 30 Apr 2007 15:12:45 +0200 |
While you can't restrict preceding-sibling to look only at members of the current group, you might be able to get somewhere with either of these approaches:
* The XPath 2.0 "intersect" operator can return those members common to two sequences of nodes, so (preceding-sibling::node() intersect current-group()) will return just those members of the current group that are on the preceding-sibling axis relative to the context.
<xsl:template match="B" mode="groups_at_root_level"> <B_new> <xsl:variable name="this_group" select="current-group()"/> <xsl:for-each-group select="$this_group" group-starting-with=" B|sub[not($this_group intersect preceding-sibling::A)]"> <xsl:apply-templates select="current-group()"/> </xsl:for-each-group> </B_new> </xsl:template>
* If, rather than using grouping constructs to select from the nodes in the source, you processed them into temporary trees, you could construct those trees exactly the way you wanted, including nesting elements in such a way that preceding-sibling would be useful. Such as:
<xsl:variable name="intermediate"> <xsl:for-each-group select="*" group-by="."> <group> <xsl:copy-of select="current-group()"/> </group> </xsl:for-each-group> <xsl:variable>
<xsl:for-each select="$intermediate/group">
... inside each group element, members of the group appear as siblings ...
</xsl:for-each>
But I'm not sure either of these are actually necessary here. You have only presented your problem in fragmentary form, so it's hard to say; but to get the result you say you want, I'd do something much simpler:> [snip]
group-starting-with=" B|sub[not($this_group intersect preceding-sibling::A)]"
group-starting-with=" B|sub[$condition1 and not($this_group intersect preceding-sibling::A[$condition2])]"
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xsl:for-each-group: start, Andrew Welch | Thread | RE: [xsl] xsl:for-each-group: start, Michael Kay |
Re: [xsl] XSL to ODF/OOXML, Steve | Date | RE: [xsl] xsl:for-each-group: start, Michael Kay |
Month |