[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: mixed content grouping by whitespace
On 13/04/2010 17:45, G. Ken Holman wrote:
As I see it and have no problems remembering it: 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="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)
</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. ________________________________________________________________________
|
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
|