【发布时间】:2015-08-24 15:42:41
【问题描述】:
我有一些 XML,我正在使用 XSLT 对其进行转换以构建链接。首先,我的模板在具有特定属性的节点上匹配,并存储该属性的值,该属性工作正常。然后我需要找到一个 id 属性与我刚刚存储的值匹配的节点。但是,当我尝试选择节点并提取 id 属性进行比较时,它会选择我所针对的节点的所有子节点,即使我指定我只需要 id 属性。如何只选择 id 属性?
XML
<div>
<bibl id="label2212" n="M">
<date n="created">19401231</date>
<title level="m">test title 1</title>
<kw type="subject">Ⓑ ...</kw><!-- EXTRA -->
<kw type="subject">Ⓔ ...</kw><!-- EXTRA -->
<kw type="subject">Ⓖ Indonesia < Southeast Asia < Asia</kw><!-- EXTRA -->
<note type="comment">Linked reference: ABIA 13, 1938/658
<xref n="label658">label658</xref>
</note>
</bibl>
<bibl id="label658" n="M">
<date n="created">19401231</date>
<title level="m">test title 2</title>
<kw type="subject">Ⓑ ...</kw><!-- EXTRA -->
<kw type="subject">Ⓔ ...</kw><!-- EXTRA -->
<kw type="subject">Ⓖ Indonesia < Southeast Asia < Asia</kw><!-- EXTRA -->
</bibl>
XSLT
<xsl:template match="note[@type = 'comment' ]/xref[@n]">
<xsl:variable name="n-xref"><xsl:value-of select="@n"/></xsl:variable>
<xsl:variable name="test"><xsl:value-of select="../../../bibl[@id]"/></xsl:variable>
<a>
<xsl:attribute name="href" select="$test"></xsl:attribute>
</a>
</xsl:for-each>-->
<xsl:apply-templates/>
</xsl:template>enter code here
运行时变量 test 包含 bibl 节点的所有子节点 我什至尝试过 select="../../../bibl[@id=$n-xref]" 也没有用
【问题讨论】:
-
你的问题不清楚。请发布您的示例的预期结果。 -- 提示:使用 key 进行交叉引用。