gpt4 book ai didi

xslt - 获取名为 xlink :href using xsl 的 xml 属性

转载 作者:行者123 更新时间:2023-12-03 15:29:21 25 4
gpt4 key购买 nike

如何获取名为 xlink:href 的属性的值xsl 模板中的 xml 节点?

我有这个 xml 节点:

<DCPType>
<HTTP>
<Get>
<OnlineResource test="hello" xlink:href="http://localhost/wms/default.aspx"
xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" />
</Get>
</HTTP>
</DCPType>

当我尝试以下 xsl 时,我收到一条错误消息,指出“未定义前缀‘xlink’。” :
<xsl:value-of select="DCPType/HTTP/Get/OnlineResource/@xlink:href" />

当我尝试这个简单的属性时,它起作用了:
<xsl:value-of select="DCPType/HTTP/Get/OnlineResource/@test" />

最佳答案

您需要先在 XSLT 中声明 XLINK namespace ,然后才能引用它。

您可以将其添加到 xsl:value-of元素:

<xsl:value-of select="DCPType/HTTP/Get/OnlineResource/@xlink:href" xmlns:xlink="http://www.w3.org/1999/xlink" />

但是,如果您需要在样式表的其他区域引用它,那么在 XSLT 的文档元素的顶部声明它会更容易:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:xlink="http://www.w3.org/1999/xlink">

顺便说一下,您不需要在样式表中使用与 XML 中使用的相同的命名空间前缀。命名空间前缀仅用作命名空间 URI 的简写。您可以像这样声明和使用 XLINK 命名空间:
<xsl:value-of select="DCPType/HTTP/Get/OnlineResource/@x-link:href"  xmlns:x-link="http://www.w3.org/1999/xlink"/>

关于xslt - 获取名为 xlink :href using xsl 的 xml 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2779550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com