xsl-list
[Top] [All Lists]

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

2011-01-31 04:57:05
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(_dot_)c(_at_)thomsondigital(_dot_)com> 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
       <footnote id="fn0010"><label>1</label><p>footnote 1</p></footnote>
XXXX</p>
<p>XXXX
       <footnote id="fn0015"><label>1</label><p>footnote 2</p></footnote>
XXXX</p>
<p>XXXX
       <footnote id="fn0020"><label>1</label><p>footnote 3</p></footnote>
XXXX</p>
<p>XXXX
       <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
       <!--<footnote id="fn0010">-->
XXXX</p>
<p>XXXX
       <!--<footnote id="fn0015">-->
XXXX</p>
<p>XXXX
       <!--<footnote id="fn0020">-->
XXXX</p>
<p>XXXX
       <!--<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.

 <xsl:template match="comment()">
   <xsl:choose>
       <xsl:when test="substring(.,2,8)='footnote'">
           <!-- do something here  -->
       </xsl:when>
       <xsl:otherwise>
           <xsl:comment><xsl:value-of select="."/></xsl:comment>
       </xsl:otherwise>
   </xsl:choose>
</xsl:template>

Anybody can throw some idea to get it done. I am definitely missing
something.

TIA,
Pankaj



-- 
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>