[英]Getting value of tag referenced by id ref
I'm trying to get a value of a tag of an element referenced by idref. 我正在尝试获取idref引用的元素的标签的值。
<ksiazka id="k2">
<title> title 1 </title>
<wydawnictwo idref="wyd1"/>
</ksiazka>
<wyd id="wyd1">
<name>Zielona Sowa</name>
</wyd>
To get title of < ksiazka > all I have to do is 要获得<ksiazka>的头衔,我要做的就是
<xsl:template match="ksiazka">
<xsl:value-of select "./title"/>
But how to get < name > out of < wyd >? 但是如何从<wyd>中获取<name>? Any suggestions?
有什么建议么?
Ok, I figured out how to do it. 好的,我想出了办法。
<xsl:key name = "wydawnictwoKEY" match= "wyd" use = "@id" />
<xsl:template match="wydawnictwo">
<xsl:copy>
<xsl:value-of select="key('wydawnictwoKEY', @idref)/name"/>
</xsl:copy>
</xsl:template>
and then 接着
<xsl:apply-templates select="wydawnictwo"/>
XSLT has a build-in mechanism to resolve cross-references. XSLT具有内置机制来解决交叉引用。 Start by defining a key at the top level of your stylesheet as:
首先在样式表的顶层定义一个键 ,如下所示:
<xsl:key name="pub" match="wyd" use="@id" />
Then you can use: 然后,您可以使用:
<xsl:value-of select="key('pub', wydawnictwo/@idref)/name"/>
to get the corresponding wyd/name
from the context of ksiazka
. 从
ksiazka
的上下文中获取相应的wyd/name
。
See a demo here: http://xsltransform.net/94AbWBE 在此处查看演示: http : //xsltransform.net/94AbWBE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.