检查 xml 文档是否包含具有特定 id 属性的元素
check if xml document contains element with a certain id attribute
我需要找出一个文档是否有一个具有特定 id 属性的节点。
我遍历节点列表,对于每个节点,我需要检查第二个文档是否包含具有相同 ID 的元素,然后执行某些操作。
我的方法是:
<xsl:variable name="variableOfDocument" select="doc(iri-to-uri('somedocument.xml'))/>
<!-- check, whether somewhere in the document, there is an element with the same id as the element currently matched -->
<xsl:if test="$variableOfDocument//*[text()[contains(.,$currentId)]]">
<!-- do something -->
</xsl:if>
但这不起作用 - 它找不到匹配项。我需要如何放置 xpath? (我正在使用 xslt 2.0)
我知道了:
由于我的文档只有带有属性的元素而没有文本节点,所以我需要这样写:
<xsl:if test="$currCompFile//*/node()/@id = $curID"/>
检查 $currCompFile 中的任何 id 属性是否与 $curID 的值匹配。
我需要找出一个文档是否有一个具有特定 id 属性的节点。
我遍历节点列表,对于每个节点,我需要检查第二个文档是否包含具有相同 ID 的元素,然后执行某些操作。
我的方法是:
<xsl:variable name="variableOfDocument" select="doc(iri-to-uri('somedocument.xml'))/>
<!-- check, whether somewhere in the document, there is an element with the same id as the element currently matched -->
<xsl:if test="$variableOfDocument//*[text()[contains(.,$currentId)]]">
<!-- do something -->
</xsl:if>
但这不起作用 - 它找不到匹配项。我需要如何放置 xpath? (我正在使用 xslt 2.0)
我知道了:
由于我的文档只有带有属性的元素而没有文本节点,所以我需要这样写:
<xsl:if test="$currCompFile//*/node()/@id = $curID"/>
检查 $currCompFile 中的任何 id 属性是否与 $curID 的值匹配。