[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
On 13/04/2010 17:45, G. Ken Holman wrote:
yes but that is still arbitrary. the difference betwen group-by and group-starting with is (to me) mainly that in the former you re-order the items to put them in groups, but in the latter you do not, and you just partition the input sequence without re-ordering. Why should the choice between ordering and not ordering be tied to names/values?
> ...
The following has two variables, one holding nodes and the other numbers. I can group the nodes into heading or not heading with almost identical code to grouping the numbers into even or odd. Just use appropriate predicates.
However if i don't want to re-order things get harder. For nodes I can make a group starting with each heading, but how do you easily partition the integers into groups starting at each 0?
If group-starting-with took a boolean expression rather than a pattern it would be a lot easier, see the commented out code at the end.
David
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:variable name="y" select="0,1,2,0,3,4"/>
<xsl:template name="main">
-->
<!-- david C-s ideal world The above woul dnot be an error and
group-starting-with would take an expression not a match, and the group would start whenever the expression was true.
so to do nodes you would have to do self::h2 as in the group-by example
(or with exists() for extra clarity rather than relying on implict boolean conversion)
</xsl:stylesheet>
This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________
Re: [xsl] mixed content grouping by whitespace
Subject: Re: [xsl] mixed content grouping by whitespace From: David Carlisle <davidc@xxxxxxxxx> Date: Tue, 13 Apr 2010 18:09:54 +0100 |
On 13/04/2010 17:45, G. Ken Holman wrote:
As I see it and have no problems remembering it:
group-by and group-adjacent are based on values, group-starting-with and group-ending-with are based on names.
yes but that is still arbitrary. the difference betwen group-by and group-starting with is (to me) mainly that in the former you re-order the items to put them in groups, but in the latter you do not, and you just partition the input sequence without re-ordering. Why should the choice between ordering and not ordering be tied to names/values?
> ...
I'm not really sure what you are trying to say there, David. And in what you are trying to say are you accommodating the feature of using a sequence in group-by= in order to place a single population member into more than one group simultaneously? I need to include a running example of that in the classroom to help convey that concept to students.
The following has two variables, one holding nodes and the other numbers. I can group the nodes into heading or not heading with almost identical code to grouping the numbers into even or odd. Just use appropriate predicates.
However if i don't want to re-order things get harder. For nodes I can make a group starting with each heading, but how do you easily partition the integers into groups starting at each 0?
If group-starting-with took a boolean expression rather than a pattern it would be a lot easier, see the commented out code at the end.
David
$ saxon9 -it main grp.xsl <?xml version="1.0" encoding="UTF-8"?> <grouping-nodes> <group> <h2>heading 1</h2> <h2>heading 2</h2> </group> <group> <p> para 1.1</p> <p> para 1.2</p> <p> para 2.1</p> <p> para 2.2</p> </group> </grouping-nodes> <grouping-items> <group>0 2 0 4</group> <group>1 3</group> </grouping-items> <grouping-nodes-without-reordering> <group> <h2>heading 1</h2> <p> para 1.1</p> <p> para 1.2</p> </group> <group> <h2>heading 2</h2> <p> para 2.1</p> <p> para 2.2</p> </group> </grouping-nodes-without-reordering>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:variable name="x"> <h2>heading 1</h2> <p> para 1.1</p> <p> para 1.2</p> <h2>heading 2</h2> <p> para 2.1</p> <p> para 2.2</p> </xsl:variable>
<xsl:variable name="y" select="0,1,2,0,3,4"/>
<xsl:template name="main">
<grouping-nodes> <xsl:for-each-group select="$x/*" group-by="exists(self::h2)"> <group> <xsl:copy-of select="current-group()"/> </group> </xsl:for-each-group> </grouping-nodes>
<grouping-items> <xsl:for-each-group select="$y" group-by=". mod 2 = 0"> <group> <xsl:copy-of select="current-group()"/> </group> </xsl:for-each-group> </grouping-items>
<grouping-nodes-without-reordering> <xsl:for-each-group select="$x/*" group-starting-with="h2"> <group> <xsl:copy-of select="current-group()"/> </group> </xsl:for-each-group> </grouping-nodes-without-reordering>
<!-- error <grouping-nodes-without-reordering> <xsl:for-each-group select="$y" group-starting-with="0"> <group> <xsl:copy-of select="current-group()"/> </group> </xsl:for-each-group> </grouping-nodes-without-reordering>
-->
<!-- david C-s ideal world The above woul dnot be an error and
group-starting-with would take an expression not a match, and the group would start whenever the expression was true.
so to do nodes you would have to do self::h2 as in the group-by example
(or with exists() for extra clarity rather than relying on implict boolean conversion)
<grouping-nodes-without-reordering> <xsl:for-each-group select="$x/*" group-starting-with="exists(self::h2)"> <group> <xsl:copy-of select="current-group()"/> </group> </xsl:for-each-group> </grouping-nodes-without-reordering>
--> </xsl:template>
</xsl:stylesheet>
________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] mixed content grouping by, G. Ken Holman | Thread | Re: [xsl] mixed content grouping by, Wendell Piez |
Re: [xsl] mixed content grouping by, G. Ken Holman | Date | Re: [xsl] The output of evaluating , Dimitre Novatchev |
Month |