[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Extract footnotes

Subject: Re: Extract footnotes
From: "J. S. Rawat" <jrawat@xxxxxxxxxxxxxx>
Date: Mon, 05 Nov 2007 09:03:01 +0530
Re:  Extract footnotes
Hi Ken,
Thanks you very much for your efforts, thanks a lot.

...JSR
At 10:12 AM 11/3/2007 -0400, you wrote:
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@xxxxxxxxxxxxxxxxxxxx
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.