我有一个XML文件,它具有许多类似命名的节点,但某些节点中的属性是唯一的。我只想输出到HTML页面中的属于某个属性值的节点。xslt 1.0 - 尝试获取特定值的节点
这里是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代码,但它获取了所有内容,而不仅仅是我想要的部分。我知道第一个“何时”正在工作,因为正确的标题(跨度标记之间)正常显示。这只是为了每个参赛作品。
<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
任何帮助将不胜感激。
这将有助于查看您期望收到的输出。 – ABach
@ABach - 增加什么输出应该是 – jjasper0729