2015-04-23 23 views
1

我有下面的XML。前面的元素计数忽略节点

<nd> 
      <fn> 
       <fnn>*</fnn> 
       <fnt> 
        <p> 
         <i>ftn 1</i> 
        </p> 
       </fnt> 
      </fn> 
      <ti> 
       <fn> 
        <fnn>*</fnn> 
        <fnt> 
         <p> 
          <i>ftn 1</i> 
         </p> 
        </fnt> 
       </fn> 
      </ti> 
      <tx> 
       <fn> 
        <fnn>1</fnn> 
        <fnt> 
         <p> 
          <i>ftn2</i> 
         </p> 
        </fnt> 
       </fn> 
       <fn> 
        <fnn>2</fnn> 
        <fnt> 
         <p> 
          <i>ftn3</i> 
         </p> 
        </fnt> 
       </fn> 
      </tx> 
     </nd> 

在这里,我要算前fnn和创建脚注,但在这里我想则会忽略的preceding::tx。我正在使用下面的XSLT。

<xsl:template match="/"> 
     <hmtl> 
     <head> 
      <title>New Version!</title> 
     </head> 
     <xsl:apply-templates/> 
      <xsl:if test="//fnn"> 
        <section class="tr_footnotes"> 
         <xsl:text disable-output-escaping="yes"><![CDATA[<hr />]]></xsl:text> 
         <xsl:apply-templates select="//page|//fnt" mode="footnote"/> 
        </section> 
       </xsl:if> 
     </hmtl> 
    </xsl:template> 

    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="fnn"> 
      <xsl:variable name="count" select="count(preceding::fnn)"/> 
     <xsl:variable name="varHeaderNote" select='concat("f",$count)'/> 
     <xsl:variable name="varFootNote" select='concat("#ftn.",$count)'/> 
     <sup> 
      <a name="{$varHeaderNote}" href="{$varFootNote}" class="tr_ftn"> 
       <xsl:value-of select="."/> 
      </a> 
     </sup> 
    </xsl:template> 
     <xsl:template match="ti"/> 

    <xsl:template match="fnt" mode="footnote"> 
     <xsl:variable name="count" select="count(preceding::fnn)"/> 
     <div class="tr_footnote"> 
      <div class="footnote"> 
       <sup> 
        <a> 
         <xsl:attribute name="name"><xsl:text>ftn.</xsl:text><xsl:value-of select="$count"/></xsl:attribute> 
         <xsl:attribute name="href"><xsl:text>#f</xsl:text><xsl:value-of select="$count"/></xsl:attribute> 
         <xsl:attribute name="class"><xsl:text>tr_ftn</xsl:text></xsl:attribute> 
         <xsl:value-of select="$count"/> 
        </a> 
       </sup> 
       <xsl:apply-templates/> 
      </div> 
     </div> 
    </xsl:template> 

这里我可以在使用<xsl:template match="ti"/>忽略ti,但泰德指望它正在考虑内部tifnn,在这里,我想忽略它和计数。而在脚注部分,我无法忽视它。

在这里头部分。

ftn.0后,将其产生ftn.2,但我想这是ftn 1

而在脚注部分有ftn.1ftn.2(这是ti脚注),这应该被忽略。

请让我知道我该如何解决这个问题。

这里是working Demo

感谢。

回答

0

我认为,你可以更改计数器:

<xsl:variable name="count" select="count(preceding::fnn[not(ancestor::ti)])"/> 
+0

这不是在脚注部分 – user3872094

+0

工作我不知道理解完全地将OBJECTIF,但试试这个方法:http://xsltransform.net/6qVRKww/8。它当然有一个更简单的方法,但它不需要更改整个代码。有必要改变计数器并将其推导为模式脚注的模板,并对fnt进行谓词。 –