Subject: Re: [xsl] Nesting elements and children using for-each-group: From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 11 Jan 2016 17:56:55 -0000 |
Hi,
Maybe I'm using the wrong XSL instruction. Maybe for-each-group is the wrong option. I've spent the last few days reading about this instruction and trying variations based on examples posted in this and other forums without success. Most of the examples seem focused on either organizing a flat structure such as HTML or pulling nested elements up to the top level.
Here's a simplified version of my source XML:
<?xml version="1.0" encoding="utf-8"?> <topic id="topica"> <title>Topic A</title> <body> <p>Random content.</p> <section id="section1"> <title>Section 1</title> <p>Random content.</p> </section> <section id="section2"> <title>Section 2</title> <p>Random content.</p> </section> <section id="section2a" outputclass="nested"> <title>Section 2a</title> <p>Random content.</p> </section> <section id="section2b" outputclass="nested"> <title>Section 2b</title> <p>Random content.</p> </section> <section id="section3"> <title>Section 3</title> <p>Random content.</p> </section> <section id="section3a" outputclass="nested"> <title>Section 3a</title> <p>Random content.</p> </section> </body> </topic>
What I want to do is nest all <section /> elements with the @outputclass="nested" attribute under the immediately preceding <section /> element that has no such attribute.
All of the sections, in turn, would follow the topic/body node rather than be nested within it.
Desired output:
<?xml version="1.0" encoding="utf-8"?> <topic id="topica"> <title>Topic A</title> <body> <p>Random content.</p> </body> <section id="section1"> <title>Section 1</title> <p>Random content.</p> </section> <section id="section2"> <title>Section 2</title> <p>Random content.</p> <section id="section2a" outputclass="nested"> <title>Section 2a</title> <p>Random content.</p> </section> <section id="section2b" outputclass="nested"> <title>Section 2b</title> <p>Random content.</p> </section> </section> <section id="section3"> <title>Section 3</title> <p>Random content.</p> <section id="section3a" outputclass="nested"> <title>Section 3a</title> <p>Random content.</p> </section> </section> </topic>
<xsl:strip-space elements="*"/> <xsl:output indent="yes"/>
<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Nesting elements and children, Mark Peters markpete | Thread | Re: [xsl] Nesting elements and chil, G. Ken Holman g.ken. |
[xsl] Nesting elements and children, Mark Peters markpete | Date | Re: [xsl] Nesting elements and chil, G. Ken Holman g.ken. |
Month |