Subject: Re: [xsl] Group and change heading element From: "Charles O'Connor coconnor@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 12 Sep 2018 18:21:39 -0000 |
Graydon and Martin, Thanks a bunch! I've learned valuable lessons about (1) the power of the identity template and (2) the need to question assumptions built into sample code found in tutorials. --Charles -----Original Message----- From: Graydon graydon@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Sent: Wednesday, September 12, 2018 2:03 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Group and change heading element On Wed, Sep 12, 2018 at 05:49:24PM -0000, Charles O'Connor coconnor@xxxxxxxxxxxx scripsit: > <root> > <body><div class="abstract"> > <h1><b>Bold</b> Intro!</h1> > <p>This is an intro <i>with <b>various</b> formatting</i> and other stuff.</p> > <p>This is a second para in the intro</p> > <h1>Methods</h1> > <p>There is no method to our madness</p> > <h1>Results</h1> > <p>The results are soooo good . . . </p> > <p> . . . they require . . . </p> > <p> . . . three paragraphs</p> > <h1>Conclusion</h1> > <p>This is all that is necessary</p> > </div></body> > </root> [snip] I'd suggest you set up the identity transform (so everything that isn't specifically matched gets copied) <xsl:template match="node() | @*"> <xsl:copy> <xsl:apply-templates select="node() | @*"/> </xsl:copy> </xsl:template> Then add a template for h1: <xsl:template match="h1"> <title> <xsl:apply-templates/> </title> </xsl:template> And then use, for the div template: <xsl:template match="div"> <abstract> <xsl:for-each-group select="*" group-starting-with="h1"> <sec> <xsl:apply-templates select="current-group()"/> </sec> </xsl:for-each-group> </abstract> </xsl:template> I've just typed this in directly to the email, I haven't tested it. But the logic should be fine even if I've got a typo somewhere. -- Graydon
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Group and change heading , Graydon graydon@xxxx | Thread | Re: [xsl] Group and change heading , Wendell Piez wapiez@ |
Re: [xsl] Group and change heading , Graydon graydon@xxxx | Date | Re: [xsl] Group and change heading , Wendell Piez wapiez@ |
Month |