xslt - check for the following node -


i've small question in xslt. need xpath validate condition. , below xml.

<root> <para>     erlanger , several associates formed syndicate acquire lease of island in west indies &#x00a3;55,000. idea mine <page num="44"/>island phosphates.  </para> <para>     <content-style font-style="bold">2.25</content-style> commission or payment promoter receives upon transfer of property company must disclosed.         <para>             board nominees of green , smith; <page num="45"/>accordingly, disclosure   </para> </para> <para>     <content-style font-style="bold">2.26</content-style> if promoter contracts company whether vendor<footnote num="57" id="fn57">         <para>             <case>                 <casename>                     <content-style font-style="italic">re leeds &#x0026; hanley theatres of varieties ltd</content-style>                 </casename> &#x005b;1902&#x005d; ch 809 (court of appeal, england)             </case>.         </para>     </footnote> or purchaser,<footnote num="58" id="fn58">         <para>             <case>                 <casename>                     <content-style font-style="italic">habib abdul rahman v abdul cader</content-style>                 </casename> (1886) 4 ky 193 (high court of straits settlements)             </case>.         </para>     </footnote> fact contractor must disclosed. </para> </root> 

and xsl below.

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0"                 xmlns:xsl="http://www.w3.org/1999/xsl/transform"                 xmlns:xs="http://www.w3.org/2001/xmlschema"                 xmlns:fn="http://www.w3.org/2005/xpath-functions"                 xmlns:ntw="number2word.uri"                 exclude-result-prefixes="ntw">     <xsl:output method="html"/>     <xsl:strip-space elements="*"/>       <xsl:variable name="thisdocument" select="document('')"/>       <xsl:template match="/">         <xsl:text disable-output-escaping="yes"><![cdata[<!doctype html>]]></xsl:text>          <html>             <head>                 <xsl:text disable-output-escaping="yes"><![cdata[</meta>]]></xsl:text>                 <title>                     <xsl:value-of select="chapter/title[1]/*"/>                 </title>                 <link rel="stylesheet" href="c:\users\u0138039\desktop\proview\sg\commentary_sg_xml-03032014\sg-business guide competition law\05192014\xslt\main.css" type="text/css"/>                 <xsl:text disable-output-escaping="yes"><![cdata[</link>]]></xsl:text>             </head>             <body>                 <xsl:apply-templates/>                 <xsl:if test="//footnote">                     <section class="tr_footnotes">                         <hr/>                         <xsl:apply-templates select="//page[not(ancestor::toc)]| //footnote" mode="footnote"/>                      </section>                 </xsl:if>             </body>         </html>     </xsl:template>      <xsl:template match="footnote">         <xsl:variable name="varheadernote" select='concat("f",@num)'/>         <xsl:variable name="varfootnote" select='concat("#ftn.",@num)'/>         <sup>             <a name="{$varheadernote}" href="{$varfootnote}" class="tr_ftn">                 <xsl:value-of select="@num"/>             </a>         </sup>     </xsl:template>      <xsl:template match="page" mode="footnote">         <xsl:processing-instruction name="pb">             <xsl:text>label='</xsl:text>             <xsl:value-of select="./@num"/>             <xsl:text>'</xsl:text>             <xsl:text>?</xsl:text>         </xsl:processing-instruction>     </xsl:template>      <xsl:template match="footnote" mode="footnote">          <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>     </xsl:stylesheet> 

here when run this, both <?pb label='44'?><?pb label='45'?>

where need condition below.

there should `footnote` following `page` , there should no `page` between `page` , `footnote` 

in simple, taking above example, there 2 page, ignoring other tags , considering page structure looks below.

page num='44' page num='45' footnote 

here want page num='45' captured , leave page num='44' since page num='44' followed page not directly footnote, pretty confusing, please let me know how can this.

the demo can found here

thanks

when match page can check whether next footnote has preceding page current page. if it's not, don't print out processing instruction since it's page without footnote.

<xsl:template match="page" mode="footnote">     <xsl:if test="following::footnote[1][preceding::page[1]/@num = current()/@num]">         <xsl:processing-instruction name="pb">             <xsl:text>label='</xsl:text>             <xsl:value-of select="./@num"/>             <xsl:text>'</xsl:text>             <xsl:text>?</xsl:text>         </xsl:processing-instruction>     </xsl:if> </xsl:template> 

see: http://xsltransform.net/eiqzdbt/3


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -