【问题标题】:how to show last two node in xslt?如何在 xslt 中显示最后两个节点?
【发布时间】:2017-07-09 08:44:56
【问题描述】:

您能帮我获取 xslt 中的最后两个节点吗?这是我的代码 http://xsltransform.net/bwdwsJ/1

期望输出

<h1>Preview your result as PDF when doctype is set to XML and your document starts with
      root element of XSL-FO. Apache FOP is used to generate the PDF
   </h1>
   <h1>Added some links to useful XSLT sites</h1>

xslt 代码

 <xsl:template match="/">
      <hmtl>
        <head>
          <title>New Version!</title>
        </head>
        <xsl:for-each select="ul/li[last() &gt;2]">
            <h1><xsl:value-of select="."/></h1>
        </xsl:for-each>
      </hmtl>
    </xsl:template>

xml

<?xml version="1.0" encoding="UTF-8"?>

    <ul>
        <li>A new XSLT engine is added: Saxon 9.5 EE, with a license (thank you Michael Kay!)</li>
        <li>XSLT 3.0 support when using the new Saxon 9.5 EE engine!</li>
        <li>Preview your result as HTML when doctype is set to HTML (see this example)</li>
        <li>Preview your result as PDF when doctype is set to XML and your document starts with root element of XSL-FO. Apache FOP is used to generate the PDF</li>
        <li>Added some links to useful XSLT sites</li>
    </ul>

【问题讨论】:

    标签: jquery xml xslt xpath xslt-1.0


    【解决方案1】:

    你可以使用下面的XPath表达式:

    /ul/li[position()>count(/ul/li)-2]
    

    【讨论】:

      【解决方案2】:

      简短但有效:ul/li[position() &amp;gt;= last()-1]

      当前处理节点的位置必须大于或等于最后一个元素的索引减1。

      显示在:http://xsltransform.net/bwdwsJ/2

      【讨论】:

        猜你喜欢
        • 2019-02-21
        • 2014-02-10
        • 1970-01-01
        • 2017-09-01
        • 2021-02-04
        • 2016-07-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多