Subject: Re: [xsl] Nested for-each-group and current-group() From: "Terry Badger terry_badger@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 11 May 2020 20:51:52 -0000 |
Rick, Think on second group you want B <xsl:for-each-group select="current-group()/*"> Try this: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" B B B version="2.0"> B B B <xsl:output indent="yes"/> B B B <xsl:template match="/"> B B B B B B B <xsl:result-document href="rick-output.xml"> B B B B B B B B B B B <xsl:apply-templates/> B B B B B B B </xsl:result-document> B B B </xsl:template> B B B <xsl:template match="root"> B B B B B B B <root> B B B B B B B B B B B <xsl:for-each-group select="*" B B B B B B B B B B B B B B B group-adjacent=" B B B B B B B B B B B B B B B B B B B if (self::topic) then B B B B B B B B B B B B B B B B B B B B B B B 1 B B B B B B B B B B B B B B B B B B B else B B B B B B B B B B B B B B B B B B B B B B B 0"> B B B B B B B B B B B B B B B <xsl:choose> B B B B B B B B B B B B B B B B B B B <xsl:when test="current-grouping-key() = 1"> B B B B B B B B B B B B B B B B B B B B B B B <ol> B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:for-each-group select="current-group()/*" B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B group-adjacent=" B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B if (self::subtopic) then B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B 1 B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B else B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B 0"> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:choose> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:when test="current-grouping-key() = 1"> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B <ul> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:apply-templates select="current-group()"/> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B </ul> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B </xsl:when> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:otherwise> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B <li> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:apply-templates select="current-group()"/> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B </li> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B </xsl:otherwise> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B </xsl:choose> B B B B B B B B B B B B B B B B B B B B B B B B B B B </xsl:for-each-group> B B B B B B B B B B B B B B B B B B B B B B B </ol> B B B B B B B B B B B B B B B B B B B </xsl:when> B B B B B B B B B B B B B B B B B B B <xsl:otherwise> B B B B B B B B B B B B B B B B B B B B B B B <xsl:apply-templates select="current-group()"/> B B B B B B B B B B B B B B B B B B B </xsl:otherwise> B B B B B B B B B B B B B B B </xsl:choose> B B B B B B B B B B B </xsl:for-each-group> B B B B B B B </root> B B B </xsl:template> B B B <xsl:template match="topic | subtopic"> B B B B B B B <li> B B B B B B B B B B B <xsl:apply-templates/> B B B B B B B </li> B B B </xsl:template> B B B <!-- Identity transform. --> B B B <xsl:template match="@* | node()"> B B B B B B B <xsl:copy copy-namespaces="no"> B B B B B B B B B B B <xsl:apply-templates select="@* | node()"/> B B B B B B B </xsl:copy> B B B </xsl:template> </xsl:stylesheet> TerryBadger On Monday, May 11, 2020, 12:36:32 PM EDT, Liam R. E. Quin liam@xxxxxxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: On Mon, 2020-05-11 at 15:47 +0000, Wendell Piez wapiez@xxxxxxxxxxxxxxx wrote: > Hi, > > Alternatively, if you wish to continue using xsl:apply-templates > idiomatically and capture all nodes in traversal without the ungainly > "current-group()/node()", you could write > > <xsl:for-each select="current-group()"> >B <xsl:apply-templates/> > </xsl:for-each> This does something slightly different in the presence of commentsB and processing instructions i think. THe coffee hasn't worked here yet. Also, Rick already has <xsl:apply-templates select="current-group()"> elsewhere in their XSLT :) Liam -- Liam Quin, https://www.delightfulcomputing.com/ Available for XML/Document/Information Architecture/XSLT/ XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. Barefoot Web-slave, antique illustrations:B http://www.fromoldbooks.org
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Nested for-each-group and, Liam R. E. Quin liam | Thread | [xsl] exercise in complex grouping, Syd Bauman s.bauman@ |
Re: [xsl] Nested for-each-group and, Liam R. E. Quin liam | Date | [xsl] exercise in complex grouping, Syd Bauman s.bauman@ |
Month |