[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: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 12 Sep 2018 17:55:12 -0000
Re:  Group and change heading element
On 12.09.2018 19:49, Charles O'Connor coconnor@xxxxxxxxxxxx wrote:

I am attempting to wrap headings and paragraphs into <sec> elements while changing the <h1> to <title>. So, given this XML

<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>

I want:

<root>
     <body>
         <abstract>
             <sec>
                 <title><bold>Bold</bold> Intro!</title>
                 <p>This is an intro <italic>with <bold>various</bold> formatting</italic> and other
                     stuff.</p>
                 <p>This is a second para in the intro</p>
             </sec>
             <sec>
                 <title>Methods</title>
                 <p>There is no method to our madness</p>
             </sec>
             <sec>
                 <title>Results</title>
                 <p>The results are soooo good . . . </p>
                 <p> . . . they require . . . </p>
                 <p> . . . three paragraphs</p>
             </sec>
             <sec>
                 <title>Conclusion</title>
                 <p>This is all that is necessary</p>
             </sec>
         </abstract>
     </body>
</root>

But with this template:

   <xsl:template match="div">
         <abstract>
             <xsl:for-each-group select="*" group-starting-with="h1">
                 <sec>
                     <title>
                         <!--<xsl:value-of select="."/>-->
                         <xsl:apply-templates/>
                     </title>
                     <xsl:for-each select="current-group()">
                         <xsl:copy>
                             <xsl:apply-templates/>
                         </xsl:copy>
                     </xsl:for-each>
                 </sec>
             </xsl:for-each-group>
         </abstract>
     </xsl:template>

As you want to wrap all elements you group into the "sec" element it seems you can use


  <xsl:for-each-group select="*" group-starting-with="h1">
    <sec>
      <xsl:apply-templates select="current-group()"/>
    </sec>
  </xsl:for-each-group>



and then write a template for those "h1" elements

  <xsl:template match="h1">
     <title>
       <xsl:apply-templates/>
     </title>
  </xsl:template>

of course together with the identity transformation template for those elements you simply want to copy.

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.