Re: [xsl] flattening and re-ordering nested notes

Subject: Re: [xsl] flattening and re-ordering nested notes
From: Walter Lee Davis <waltd@xxxxxxxxxxxx>
Date: Mon, 18 Aug 2008 17:42:58 -0400
On Aug 18, 2008, at 4:45 PM, Andrew Welch wrote:

I wrote:

<xsl:template match="document">
       <xsl:copy>
               <xsl:apply-templates select="@*|node()"/>
       </xsl:copy>
       <xsl:apply-templates select="//note" mode="notes"/>
</xsl:template>

you have:


<xsl:template match="document">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:apply-templates select="//note[not (@type='margin' or
@type='sourcenote')]" mode="notes"/>
</xsl:copy>
</xsl:template>

The apply-templates for notes has moved back inside xsl:copy - it needs to be outside for the <note>'s to be output after <document>.


If you look back to my pastie, you'll see that I did want the notes inside the document, just after any other elements (divs, mostly) and all at the same level as any other content within the document.


Here's what I ended up with, and it is working:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="note" mode="notes">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="note[@type !='margin' and @type != 'sourcenote']"/>


<xsl:template match="document">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:apply-templates select="//note[@type !='margin' and @type != 'sourcenote']" mode="notes"/>
</xsl:copy>
</xsl:template>


</xsl:stylesheet>


Thanks again very much for your help, you saved the day.


Walter

Current Thread