Re: [xsl] Group and change heading element

Subject: Re: [xsl] Group and change heading element
From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 13 Sep 2018 20:55:42 -0000
Hi,

Also under XSLT 3.0 we have

<xsl:mode on-no-match="shallow-copy"/>

which replaces the built-in template for anything with a template
(matching in "no mode") that copies it and traverses to its attributes
and children - i.e. with an identity template. So you don't have to
write one.

Some might say this makes XSLT harder to understand. Others might say
easier. :-)

Cheers, Wendell


On Wed, Sep 12, 2018 at 2:22 PM, Charles O'Connor
coconnor@xxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> 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
> 



-- 
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^

Current Thread