重要なお知らせ

「教えて! goo」は2025年9月17日(水)をもちまして、サービスを終了いたします。詳細はこちら>

電子書籍の厳選無料作品が豊富!

こんにちは

<a>
 <b>bb</b>
 <c>cc</c>
 <d>dd</d>
</a>
<a>
 <c>cc</c>
 <d>dd</d>
 <c>cc</c>
 <d>dd</d>
</a>

といった不規則な構造のxmlで、例えば10番目以降の<a>内の<d>は表示しないといった処理をしたいと思っています。

xslを

<xsl:template match="a">
 <xsl:number />
 <xsl:apply-templates />
</xsl:template>

<xsl:template match="b">
 <xsl:apply-templates />
</xsl;template>

<xsl:template match="c">
 <xsl:apply-templates />
</xsl;template>

<xsl:template match="d">
 <xsl:if test="ナンバーの値 < 10">
 <xsl:apply-templates />
 </xsl:if>
</xsl;template>

と書き、aのテンプレート内で指定した<xsl:number />の値をdのテンプレート内の<xsl:if >に持ってくる方法はあるでしょうか?

A 回答 (1件)

<xsl:number />の値を持ってくるということはできないですが


次のように書くことができます。
<xsl:template match="d">
 <xsl:if test="ナンバーの値 < 10">
 <xsl:apply-templates />
 </xsl:if>
</xsl;template>

<xsl:template match="//a[position() &lt; 10]/d">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="//a[position() &gt;= 10]/d">
</xsl:template>

意味:
10番目までの<a>内の<d>は表示
10番目以降の<a>内の<d>は表示しない
    • good
    • 0
この回答へのお礼

ありがとうございました。

お礼日時:2006/04/20 23:09

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!