Question

I've the below sample xml tree.

-root
  -para
   -page
   -footnum
  -para
   -footnum
  -para
   -footnum
  -para
   -page
   -footnum

I want to apply templates on the first footnum whose preceding is page. From inside the footnum template. here below para there will be even more nodesbut here i want to apply-template only to the first footnum followed by page,, whether it is in same para or different.

The code i tried is as below.

    <xsl:template match="footnote" mode="footnote">
   <xsl:variable name="rt">
<xsl:value-of select="//page/@num/following::footnote[1]/@num"/>   
   </xsl:variable>
   <xsl:value-of select="$rt"/>
 <xsl:if test="contains($rt,@num)">
   <xsl:variable name="op">&#60;</xsl:variable>
<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="cl">&#62;</xsl:variable>
<xsl:value-of select="concat($op,'?pb label=',$apos,./@num,$apos,'?',$cl)"/>
   </xsl:if>
        <div class="tr_footnote">
            <div class="footnote">
                <sup>
                <a>
                        <xsl:attribute name="name"><xsl:text>ftn.</xsl:text><xsl:value-of select="@num"/></xsl:attribute>
                        <xsl:attribute name="href"><xsl:text>#f</xsl:text><xsl:value-of select="@num"/></xsl:attribute>
                        <xsl:attribute name="class"><xsl:text>tr_ftn</xsl:text></xsl:attribute>
                        <xsl:value-of select="@num"/>
                    </a>
                </sup>

             <xsl:apply-templates/>
            </div>
        </div>
    </xsl:template>

Update:

here when i'm running this template, it is giving me before which footnotes the number is to be placed, but here i'm getting the footnote number, but not the pagenumber. please let me know how i can retrieve the page number.

here it is applying templates for all the footnums. please let me know where am i going wrong.

Thanks

Was it helpful?

Solution

You are already in the footnote context. To get the first preceding page node, you must use

<xsl:variable name="rt" select="preceding-sibling::*[1][local-name()='page']/@num"/>

OTHER TIPS

If (as I think you are saying) you want to call apply-templates to the first footnum with a preceding page element, then your first problem is that the apply-templates instruction in your sample code applies to the page element, not to the footnum element.

Your second problem (whether the error is in your code or in your problem description) is that you say you wish to do this work only in some cases (it's not clear to me what conditions you have in mind -- one footnum per document, or once per page element on the first footnum following that page element, or something else), but you don't seem to have any test in your code that tests for the condition you have in mind. The test in your conditional is preceding::page[1], which is synonymous (as a Boolean) with preceding::page, and which excludes all those footnum elements which appear before any page element in the document, and includes all the others.

Assuming that your page elements mark page breaks, and your footnum elements mark footnote numbers, and what you want is to do something special for the first footnote (if any) on each page [if that's not right, you'll have to make the appropriate adjustments to the solution], then you need to find an XPath expression that returns true for the first footnote on each page, and not for the others.

What is the crucial characteristic here of the first footnum on each page? That there is no other footnum element between it and the immediately preceding page. So we could write (not tested):

<xsl:variable name="mypage" as="element(page)?"
  select="preceding::page[1]"/>
<xsl:variable name="preceding-footnum-on-same-page"
  as="element(footnum)?"
  select="preceding::footnum[preceding::page[. is $mypage]]"/>
<xsl:if test="$mypage and not($preceding-footnum-on-same-page)">
  ... do your stuff here ...
</xsl:if>

Another way to formulate it is: the current node is the first footnum on the current page if, when we find the current page and then find its first footnum, it's the current node.

<xsl:if test=". is ./preceding::page[1]/following::footnum[1]">
  ...
</xsl:if>

I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top