[英]How to select child of an ancestor via XPath?
我有一個類似於以下內容的XML結構:
<a>
<b>
<c id="2.3">
</c>
</b>
<d>
<e>
<f>
</f>
</e>
</d>
</a>
我在"f"
模板中,我想when
其中對c
的第一個id
進行測試,例如:
<xsl:template match="f">
<xsl:choose>
<xsl:when test="substring-before(../../../c/@id, '.') = '2'">
<xsl:text>Successful</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
上面的代碼不起作用!
誰能建議我一種使它起作用的方法?
提前thnx!
因為祖先和c之間有b
。
這應該工作:
substring-before(../../../b/c/@id, '.') = '2'
(假設第二個<b>
應該是</b>
)
相對路徑很好,但有時更明確些很有用。
<xsl:template match="f">
<xsl:choose>
<xsl:when test="substring-before(ancestor::a[1]/b/c/@id, '.') = '2'">
<xsl:text>Successful</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.