質問
どのようにカウンター内xsl:各ループにその数を反映した現在の要素を処理します。
例えば、私のソースXML
<books>
<book>
<title>The Unbearable Lightness of Being </title>
</book>
<book>
<title>Narcissus and Goldmund</title>
</book>
<book>
<title>Choke</title>
</book>
</books>
いを取り付ける際に使用します。:
<newBooks>
<newBook>
<countNo>1</countNo>
<title>The Unbearable Lightness of Being </title>
</newBook>
<newBook>
<countNo>2</countNo>
<title>Narcissus and Goldmund</title>
</newBook>
<newBook>
<countNo>3</countNo>
<title>Choke</title>
</newBook>
</newBooks>
は、XSLT変更:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<newBooks>
<xsl:for-each select="books/book">
<newBook>
<countNo>???</countNo>
<title>
<xsl:value-of select="title"/>
</title>
</newBook>
</xsl:for-each>
</newBooks>
</xsl:template>
</xsl:stylesheet>
そのかしていく。.あな標準キーワードまたはんだとして宣言する必要がある変数を増やすい内側のループ?
としての問題は長いんだろうと期待を一線または単語の答え:)
解決
position()
.E.G.:
<countNo><xsl:value-of select="position()" /></countNo>
他のヒント
みの挿入 <xsl:number format="1. "/><xsl:value-of select="."/><xsl:text>
の???.
注意"1. この数値フォーマット.詳細情報: こちらの
う:
<xsl:value-of select="count(preceding-sibling::*) + 1" />
編集 -た脳凍結があり、位置()はストレート!
を運営することも可能です諸条件の位置(使用することによっても多くのシナリオ.
用例
<xsl:if test="(position( )) = 1">
//Show header only once
</xsl:if>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<newBooks>
<xsl:for-each select="books/book">
<newBook>
<countNo><xsl:value-of select="position()"/></countNo>
<title>
<xsl:value-of select="title"/>
</title>
</newBook>
</xsl:for-each>
</newBooks>
</xsl:template>
</xsl:stylesheet>
所属していません StackOverflow