所以我需要在if语句中访问一个嵌套元素。
下面你可以看到我使用的XML的例子。
<Publication>
<PubName>Avoid the Consumer Apps - How to Collaborate Securely and Productively in the Finance Sector</PubName>
<Attributes>
<Attribute>
<AttributeName>Type</AttributeName>
<Value>Webinar</Value>
<ValueText>Webinar</ValueText>
</Attribute>
</Attributes>
</Publication>
这里是我使用的XSLT代码,用来尝试访问 Webinar
值。
<xsl:for-each select="TradePub.com/PublicationTable/Publication">
<xsl:if test="Attributes/Attribute/Value='Webinar'">
<tr>
<td><xsl:value-of select="PubName"/></td>
<td><xsl:value-of select="PubCode"/></td>
</tr>
</xsl:if>
</xsl:for-each>
但这并没有返回任何东西,所以我想知道我怎么能访问 Value
元素?
使用一个谓词在 Value
元素是这样的。
<xsl:for-each select="TradePub.com/PublicationTable/Publication">
<xsl:if test="Attributes/Attribute[Value!='Webinar']">
<tr>
<td><xsl:value-of select="PubName"/></td>
<td><xsl:value-of select="PubCode"/></td>
</tr>
</xsl:if>
</xsl:for-each>
另一个你没有得到任何输出的问题是,你的样本中的IF -lause是FALSE。要想在给定的样本中得到所需的输出,请使用
<xsl:if test="Attributes/Attribute[Value='Webinar']">
而不是。那么,输出将是
<tr>
<td>Avoid the Consumer Apps - How to Collaborate Securely and Productively in the Finance Sector</td>
<td/> <!-- No 'PubCode' element present -->
</tr>