Subject: Re: [xsl] Process the following group From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 7 Jul 2022 19:22:01 -0000 |
Hey Rick, I think this is much easier if instead of conceiving of grouping by div level, then subgrouping, you go straight to the groups including their subgroups. This suggests to me not a group-adjacent but a group-starting-with pattern in your for-each-group <xsl:for-each-group group-starting-with="h1"> current group is every h1 followed by everything up to the next h1 </xsl:for-each> Or is there something I am missing? Also - in your case, local-name(current-group()[1]) is the same as current-grouping-key() is it not? Good luck, Wendell On Thu, Jul 7, 2022 at 3:10 PM rick@xxxxxxxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Hi All, > > > > I have something like this: > > > > <?xml version="1.0" encoding="UTF-8"?> > > <root> > > <div1/> > > <div1/> > > <div2/> > > <div2/> > > <div1/> > > </root> > > > > And I want to end up with this: > > > > <?xml version="1.0" encoding="UTF-8"?> > > <root> > > <div1/> > > <div1> > > <div2/> > > <div2/> > > </div1> > > <div1/> > > </root> > > > > Here is my stylesheet. When I am the last in the <div1> group, I want to > process the following <div2> group, if there is one. > > > > <?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" > > xmlns:math="http://www.w3.org/2005/xpath-functions/math" > > exclude-result-prefixes="xs math" > > version="3.0" expand-text="yes"> > > > > <xsl:output indent="yes"/> > > > > <xsl:template match="/root"> > > <root> > > <xsl:for-each-group select="*" group-adjacent="local-name()"> > > <xsl:choose> > > <xsl:when test="local-name(current-group()[1])='div1'"> > > <xsl:apply-templates select="current-group()"/> > > </xsl:when> > > </xsl:choose> > > </xsl:for-each-group> > > </root> > > </xsl:template> > > > > <xsl:template match="div1"> > > <div1> > > <!-- Am I the last in the group? --> > > <xsl:if test="position()=last()"> > > <xsl:comment>I want process the entire following div2 > group in here.</xsl:comment> > > </xsl:if> > > </div1> > > </xsl:template> > > > > </xsl:stylesheet> > > > > Thanks for any pointers you can provide. > > > > Rick > > > > Rick Quatro > > Carmen Publishing Inc. > > 585-729-6746 > > rick@xxxxxxxxxxxxxxx > > http://www.frameexpert.com/store > > > > > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/174322> (by > email <>) > -- ...Wendell Piez... ...wendell -at- nist -dot- gov... ...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org... ...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Process the following gro, Martin Honnen martin | Thread | Re: [xsl] Process the following gro, rick@xxxxxxxxxxxxxx |
Re: [xsl] Process the following gro, Martin Honnen martin | Date | Re: [xsl] Process the following gro, rick@xxxxxxxxxxxxxx |
Month |