[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Get the element to original position XSLT 1.0


Subject: Re: [xsl] Get the element to original position XSLT 1.0
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Mon, 31 Jan 2011 16:26:35 +0530

The following stylesheet (seems like a naive algorithm for this
problem) seems to work:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

    <xsl:output method="xml" indent="yes" />

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

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

   <xsl:template match="footnote" />

   <xsl:template match="comment()">
	<xsl:variable name="commentFootnoteId"
select="substring-before(substring-after(., '&quot;'), '&quot;')" />
	<xsl:copy-of select="/chapter/footnote[@id = $commentFootnoteId]" />
   </xsl:template>

</xsl:stylesheet>

On Mon, Jan 31, 2011 at 1:26 PM,  <pankaj.c@xxxxxxxxxxxxxxxxxx> wrote:
> Hello all,
>
> I've a requirement wherein I am moving all the text footnotes to endnotes,
> which I done in the following manner:
>
> <chapter>
> <section>
> <p>XXXX
> B  B  B  B <footnote id="fn0010"><label>1</label><p>footnote
1</p></footnote>
> XXXX</p>
> <p>XXXX
> B  B  B  B <footnote id="fn0015"><label>1</label><p>footnote
2</p></footnote>
> XXXX</p>
> <p>XXXX
> B  B  B  B <footnote id="fn0020"><label>1</label><p>footnote
3</p></footnote>
> XXXX</p>
> <p>XXXX
> B  B  B  B <footnote id="fn0025"><label>1</label><p>footnote
3</p></footnote>
> XXXX</p>
>
> --------
> --------------
> </section>
> </chapter>
>
> I've been able to move all my footnotes at the end as below, while keeping
> the flag (comment <footnote> elements) for reverting bak to orininal xml
> <chapter>
> <p>XXXX
> B  B  B  B <!--<footnote id="fn0010">-->
> XXXX</p>
> <p>XXXX
> B  B  B  B <!--<footnote id="fn0015">-->
> XXXX</p>
> <p>XXXX
> B  B  B  B <!--<footnote id="fn0020">-->
> XXXX</p>
> <p>XXXX
> B  B  B  B <!--<footnote id="fn0025">-->
> XXXX</p>
>
> <footnote id="fn0010"><label>1</label><p>footnote 1</p></footnote>
> <footnote id="fn0015"><label>1</label><p>footnote 2</p></footnote>
> <footnote id="fn0020"><label>1</label><p>footnote 3</p></footnote>
> <footnote id="fn0025"><label>1</label><p>footnote 4</p></footnote>
> </chapter>
>
> All is well and fine till now, but now I am bit struggling with
> re-transforming back. I understand that I need to match @id of commented
> text <footnote> with the moved <footnote id="fn0010"> to get at the right
> position.
>
> B <xsl:template match="comment()">
> B  B <xsl:choose>
> B  B  B  B <xsl:when test="substring(.,2,8)='footnote'">
> B  B  B  B  B  B <!-- do something here B -->
> B  B  B  B </xsl:when>
> B  B  B  B <xsl:otherwise>
> B  B  B  B  B  B <xsl:comment><xsl:value-of select="."/></xsl:comment>
> B  B  B  B </xsl:otherwise>
> B  B </xsl:choose>
> </xsl:template>
>
> Anybody can throw some idea to get it done. I am definitely missing
> something.
>
> TIA,
> Pankaj



--
Regards,
Mukul Gandhi


Current Thread
Keywords
xml