It ends the first inner group at the first element because it matches the
first condition, p[@class='CBNoteBody']; it ends the second inner group at the
second element because it matches the second condition
p[@class='CBBodyIndented'][@style='margin-left:96px;'], and it ends the third
inner group at the third element because everything after the last matching
element goes in a final group regardless.
Michael Kay
Saxonica
> On 6 Jan 2023, at 14:42, rick@xxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hi All,
>
> I am trying to add some hierarchy to flat content. I have this as an input
file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
> <p class="CBNote"/>
> <p class="CBNoteBody"/>
> <p class="CBBodyIndented" style="margin-left:96px;"/>
> <p class="CBBodyIndented"/>
> <p class="CBBody"/>
> </root>
>
> This is my desired output:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
> <div class="note">
> <div class="note-header">
> <p class="CBNote"/>
> </div>
> <div class="note-content">
> <p class="CBNoteBody"/>
> <p class="CBBodyIndented" style="margin-left:96px;"/>
> </div>
> </div>
> <p class="CBBodyIndented"/>
> <p class="CBBody"/>
> </root>
>
> After the note-header, the bottom boundary of the note content is either one
of these:
>
>
p[@class='CBNoteBody']|p[@class='CBBodyIndented'][@style='margin-left:96px;']
>
> Here is my stylesheet:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform
<http://www.w3.org/1999/XSL/Transform>"
> xmlns:xs="http://www.w3.org/2001/XMLSchema
<http://www.w3.org/2001/XMLSchema>"
> xmlns:math="http://www.w3.org/2005/xpath-functions/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">
> <xsl:copy>
> <xsl:for-each-group select="*"
group-starting-with="p[@class='CBNote']">
> <xsl:choose>
> <xsl:when test="self::p[@class='CBNote']">
> <div class="note">
> <div class="note-header">
> <xsl:copy-of select="."/>
> </div>
> <xsl:for-each-group
select="tail(current-group())"
group-ending-with="p[@class='CBNoteBody']|p[@class='CBBodyIndented'][@style='
margin-left:96px;']">
> <xsl:copy-of
select="current-group()[1]"></xsl:copy-of>
> </xsl:for-each-group>
> </div>
> </xsl:when>
> </xsl:choose>
> </xsl:for-each-group>
> </xsl:copy>
> </xsl:template>
>
> <xsl:mode on-no-match="shallow-skip"/>
>
> </xsl:stylesheet>
>
> Here is my current output:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
> <div class="note">
> <div class="note-header">
> <p class="CBNote"/>
> </div>
> <p class="CBNoteBody"/>
> <p class="CBBodyIndented" style="margin-left:96px;"/>
> <p class="CBBodyIndented"/>
> </div>
> </root>
>
> It looks like my group-ending-with is giving me 3 groups instead of 2 like I
expected. Any pointers will be appreciated. Thank you.
>
> Rick
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/3500899> (by
email <>)
|