|
Subject: RE: [xsl] Grouping by attribute From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Mon, 19 Oct 2009 14:13:35 +0100 |
The essence of the solution is
<xsl:template match="contentSection">
<h1>Title</h1>
<xsl:for-each-group select="*" group-starting-with="headline">
<xsl:choose>
<xsl:when test="headline">
<level2>
<xsl:apply-templates select="current-group()"/>
</level2>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</
</
</
Regards,
Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay
> -----Original Message-----
> From: Jostein Austvik Jacobsen [mailto:josteinaj@xxxxxxxxx]
> Sent: 19 October 2009 13:18
> To: xsl-list
> Subject: [xsl] Grouping by attribute
>
> I've got this flat-structured XML:
>
> <document>
> <metaData>
> <title>Title</title>
> <publisher>Publisher</publisher>
> </metaData>
> <contentSection>
> <p>text</p>
>
> <headline level="2">Headline</headline>
> <p>text</p>
> <p>text</p>
>
> <headline level="2">Section</headline>
> <p>text</p>
> <pagenum id="page2"/>
> <p>text</p>
> <headline level="3">Subsection</headline>
> <p>text</p>
>
> <headline level="2">Section</headline>
> <p>text</p>
> <p>text</p>
> </contentSection>
> </document>
>
> And want it transformed to this XML:
>
> <body>
> <level1>
> <h1>Title</h1>
> <p>text</p>
>
> <level2>
> <h2>Headline</h2>
> <p>text</p>
> <p>text</p>
> </level2>
>
> <level2>
> <h2>Section</h2>
> <p>text</p>
> <pagenum id="page2"/>
> <p>text</p>
> <level3>
> <h3>Subsection</h3>
> <p>text</p>
> </level3>
> </level2>
>
> <level2>
> <h2>Section</h2>
> <p>text</p>
> <p>text</p>
> </level2>
> </level1>
> </body>
>
> How would I do that using XSLT? XSLT 2.0 solutions are ok.
>
> Regards
> Jostein
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Grouping by attribute, Martin Honnen | Thread | Re: [xsl] Grouping by attribute, Jostein Austvik Jaco |
| Re: [xsl] Grouping by attribute, Martin Honnen | Date | [xsl] Replace one entity with anoth, Keith Gilbert |
| Month |