我有下面的XML
。趕上第一次出現的值
<chapter num="1">
<section level="sect2">
<page>22</page>
</section>
<section level="sect3">
<page>23</page>
</section>
</chapter>
這裏我試圖得到第一個出現<page>
。
我正在使用下面的XSLT。
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 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>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="chapter">
<section class="tr_chapter">
<xsl:value-of select="//page[1]/text()"/>
<div class="chapter">
</div>
</section>
</xsl:template>
</xsl:stylesheet>
但輸出,我得到所有的page
valyes印。我只想要第一個。
電流輸出。
<!DOCTYPE html>
<html>
<body>
<section class="tr_chapter">2223
<div class="chapter">
</div>
</section>
</body>
</html>
的page
值都在這裏印刷<section class="tr_chapter">
後,我想只有但我得到 這裏我使用//page[1]/text()
,因爲我不知道該page
來自內section
,它是隨機的。
請讓我知道如何我只能得到第一page
價值。
這裏是改造http://xsltransform.net/3NzcBsR
感謝
只使用'page [1]/text()' – 2014-10-08 10:39:14
它不會打印任何東西@ JoelM.Lamsen,我用轉換鏈接更新了我的問題。 – user3872094 2014-10-08 10:42:52
oops,應該是'descendant :: page [1]/text()' – 2014-10-08 11:01:38