At 2007-11-03 12:24 +0530, J. S. Rawat wrote:
Can anybody let me know how to extract "footnote" from paragraph and
write it to end of the section.
This is an exercise in my class for creating end notes from footnotes.
Below is what I am trying to do
Input
<section>
<para>111...<footnote label="1" id="f1"><para>First
fnt</para></footnote> 222... <footnote label="2"
id="f2"><para>second fnt</para></footnote> </para>
<para>333...<footnote label="3" id="f3"><para>Third
fnt</para></footnote> ...</para>
</section>
Required Output
<level>
<para>111....222 .... </para>
<para>333... ...</para>
<footnote label="1" id="f1"><para>First fnt</para></footnote>
<footnote label="2" id="f2"><para>second fnt</para></footnote>
<footnote label="3" id="f3"><para>Third fnt</para></footnote>
</level>
<xsl:template match="section">
<level>
<xsl:apply-templates/>
<xsl:if test="descendant::*[self::footnote]">
<xsl:apply-templates select="descendant::*[self::section//footnote]"/>
</xsl:if>
</level>
</xsl:template>
<xsl:template match="para">
<xsl:copy>
<xsl:apply-templates select="descendant::*[not(self::footnote)]"/>
</xsl:copy>
</xsl:template>
Your problem is trying to do too much imperatively rather than
declaratively. You are treating this like a programming language
rather than a templating language.
BTW, your <xsl:if> isn't required because if there are no
descendants, then nothing gets pushed.
Also, I feel your predicates are misleading and lengthy, and can be
expressed far more succinctly.
In the solution below I'm using modes so that footnotes are handled
in two different ways at two different times. Note how I'm "letting
things happen" with the template rules, rather than "forcing things to happen".
I hope this helps.
. . . . . . . . . . . Ken
t:\ftemp>type rawat.xml
<section>
<para>111...<footnote label="1" id="f1"><para>First
fnt</para></footnote> 222...
<footnote label="2" id="f2"><para>second fnt</para></footnote> </para>
<para>333...<footnote label="3" id="f3"><para>Third
fnt</para></footnote> ...</para>
</section>
t:\ftemp>type rawat.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="section">
<level>
<!--do the body of the section-->
<xsl:apply-templates/>
<!--do the end notes for the section-->
<xsl:apply-templates select=".//footnote" mode="end-notes"/>
</level>
</xsl:template>
<xsl:template match="footnote">
<!--do nothing when first encountered-->
</xsl:template>
<xsl:template match="footnote" mode="end-notes">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()"><!--identity for all other nodes-->
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
t:\ftemp>xslt rawat.xml rawat.xsl con
<?xml version="1.0" encoding="utf-8"?>
<level>
<para>111... 222... </para>
<para>333... ...</para>
<footnote label="1" id="f1">
<para>First fnt</para>
</footnote>
<footnote label="2" id="f2">
<para>second fnt</para>
</footnote>
<footnote label="3" id="f3">
<para>Third fnt</para>
</footnote>
</level>
t:\ftemp>
--
Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds: publicly-available developer resources and training
G. Ken Holman mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
--~------------------------------------------------------------------
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>
--~--