[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Two possible group-ending-with nodes

Subject: Re: Two possible group-ending-with nodes
From: "Michael Kay michaelkay90@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 6 Jan 2023 15:04:05 -0000
Re:  Two possible group-ending-with nodes
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 <>)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.