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

Re: Group and change heading element

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

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.