同じような名前のノードが多数ある XML ファイルを取得しましたが、特定のノード内の属性は一意です。特定の属性値に該当するノードのみをHTMLページに出力したい。
xml は次のとおりです。
<document>
<component>
<section>
<templateId value="temp_1" />
<entry>
<act>
<code displayName="temp_1:code_1" />
</act>
</entry>
<entry>
<act>
<code displayName="temp_1:code_2" />
</act>
</entry>
<entry>
<act>
<code displayName="temp_1:code_3" />
</act>
</entry>
</section>
<section>
<templateId value="temp_2" />
<entry>
<act>
<code displayName="temp_2:code_1" />
</act>
</entry>
<entry>
<act>
<code displayName="temp_2:code_2" />
</act>
</entry>
</section>
</component>
</document>
この特定の例から、temp_2 の templateId 値を持つセクションからのみ displayName 値を取得したいと考えています。これは私が使用している XSL コードですが、必要なセクションだけでなく、すべてを取得しています。正しいヘッダー (span タグの間) が適切に表示されているため、最初の「いつ」が機能していることがわかります。これは、エントリを介した for-each です。
<xsl:tempalte match="/">
<xsl:choose>
<xsl:when test="//templateId/@value='temp_2'">
<div style="margin-bottom: 5px; padding: 5px; border-bottom: 1px solid #000000;">
<span style="font-weight: bold;">Template 2: </span>
<br />
<xsl:choose>
<xsl:when test="count(//section/entry) != 0">
<xsl:for-each select="//section/entry">
<xsl:choose>
<xsl:when test="position() = 1">
<xsl:value-of select="act/code/@displayName" />
</xsl:when>
<xsl:otherwise>
<br/>
<xsl:value-of select="act/code/@displayName" />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
No codes to display
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:when>
</xsl:choose>
</xsl:template>
次のように表示されます。
temp_2:code_1
<br>temp_2:code_2
どんな助けでも大歓迎です。