关于xml:在select语句中使用变量作为前缀 | 珊瑚贝

Using variable as a prefix in the select statement


我有一个源 XML 文件,它带有动态(生成的)命名空间前缀,但该命名空间的 URI 是静态的。我需要通过 URI 获取这个生成的前缀并在我的 XSL 样式表中使用它。

源 XML:

1
2
3
4
5
6
7
<rdf:RDF
       xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
       xmlns:j.4=“http://www.w3.org/2004/02/skos/core#”>
    <rdf:Description>
        <j.4:prefLabel>TestNode</j.4:prefLabel>
    </rdf:Description>
</rdf:RDF>

XSL 样式表:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<xsl:stylesheet xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”
                xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
                xmlns:xsd=“http://www.w3.org/2001/XMLSchema#”
                xmlns:skos=“http://www.w3.org/2004/02/skos/core#”
                xmlns:j.4=“http://www.w3.org/2004/02/skos/core#”
                exclude-result-prefixes=“xsl skos rdf xsd”
                version=“1.0”>

    <xsl:output method=“xml” version=“1.0” encoding=“UTF-8”
                indent=“yes” omit-xml-declaration=“yes” />

    <xsl:variable name=“skosprefix” select=“name(//rdf:RDF/namespace::*[. = ‘http://www.w3.org/2004/02/skos/core#’])” />

    <xsl:template match=“//rdf:RDF/rdf:Description”>
        <node>
            <xsl:value-of select=“j.4:prefLabel”/>
        </node>
    </xsl:template>

</xsl:stylesheet>

所以在我的 XSL 样式表(选择语句)中,我想使用类似 $skosprefix:prefLabel 的东西而不是 j.4:prefLabel 来获取生成的 XML:

1
<node>TestNode</node>

如何使用 XSLT 1.0 实现它?


你可以使用类似

的东西

1
<xsl:value-of select=“*[name() = ‘j.4:prefLabel'”/>

如果变量中有命名空间(此处为 nsuri),则可以使用:

1
<xsl:value-of select=“*[namespace-uri() = $nsuri and local-name() = ‘prefLabel’]”/>
  • 感谢您的回答,但不幸的是它不会解决问题。我不想在我的 select 语句中使用 \\’j.4\\’,因为它提前是 “unknown”。唯一知道的是该名称空间的 URI。
  • 伟大的!谢谢!它按预期工作,但您错过了 select 语句中的右括号。在我接受您的回答之前,您可以添加它吗?


来源:https://www.codenong.com/43233529/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9922.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?