On 12.09.2018 19:49, Charles O'Connor coconnor(_at_)ariessys(_dot_)com 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.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--