XSLT 中的 ends-with 和 namespace-uri
ends-with and namespace-uri in XSTL
输入:
<soapenv:Envelope xmlns:ser="http://service.foo.com"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:com.foobar.to"
xmlns:wor="http://ffffff.aaa.com:443/AAA/services/Bar">
<soapenv:Body>
<ser:submit>
<urn:question>
<wor:item>1</wor:item>
</urn:question>
</ser:submit>
</soapenv:Body>
</soapenv:Envelope>
预期输出:
<soapenv:Envelope xmlns:ser="http://service.foo.com"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:com.foobar.to"
xmlns:wor="urn:com.foobar.to">
<soapenv:Body>
<ser:submit>
<urn:question>
<wor:item>1</wor:item>
</urn:question>
</ser:submit>
</soapenv:Body>
</soapenv:Envelope>
这当前用于将命名空间与特定 URI 匹配。
<xsl:template match="*[namespace-uri()='http://ffffff.aaa.com:443/AAA/services/Bar']">
<xsl:element name="{name()}" namespace="urn:com.foobar.to">
<xsl:copy-of select="namespace::*[name()]"/>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>
我正在尝试修复以上内容以匹配任何以 /AAA/services/Bar
结尾的内容
我认为使用 2.0 会起作用,但它不起作用。
<xsl:template match="*[ends-with(namespace-uri(), '/AAA/services/Bar')]">
我如何在 XSTL 1.0 or/and XSTL 2.0 中执行此操作?
谢谢
您的尝试:
<xsl:template match="*[ends-with(namespace-uri(), '/AAA/services/Bar')]">
将在 XSLT 2.0 中工作,如您在此处所见:
https://xsltfiddle.liberty-development.net/aB9NKE
在 XSLT 1.0 中,不支持 ends-with()
函数,您需要执行如下操作:
<xsl:template match="*[substring(namespace-uri(), string-length(namespace-uri()) - 16) = '/AAA/services/Bar']">
输入:
<soapenv:Envelope xmlns:ser="http://service.foo.com"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:com.foobar.to"
xmlns:wor="http://ffffff.aaa.com:443/AAA/services/Bar">
<soapenv:Body>
<ser:submit>
<urn:question>
<wor:item>1</wor:item>
</urn:question>
</ser:submit>
</soapenv:Body>
</soapenv:Envelope>
预期输出:
<soapenv:Envelope xmlns:ser="http://service.foo.com"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:com.foobar.to"
xmlns:wor="urn:com.foobar.to">
<soapenv:Body>
<ser:submit>
<urn:question>
<wor:item>1</wor:item>
</urn:question>
</ser:submit>
</soapenv:Body>
</soapenv:Envelope>
这当前用于将命名空间与特定 URI 匹配。
<xsl:template match="*[namespace-uri()='http://ffffff.aaa.com:443/AAA/services/Bar']">
<xsl:element name="{name()}" namespace="urn:com.foobar.to">
<xsl:copy-of select="namespace::*[name()]"/>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>
我正在尝试修复以上内容以匹配任何以 /AAA/services/Bar
我认为使用 2.0 会起作用,但它不起作用。
<xsl:template match="*[ends-with(namespace-uri(), '/AAA/services/Bar')]">
我如何在 XSTL 1.0 or/and XSTL 2.0 中执行此操作?
谢谢
您的尝试:
<xsl:template match="*[ends-with(namespace-uri(), '/AAA/services/Bar')]">
将在 XSLT 2.0 中工作,如您在此处所见:
https://xsltfiddle.liberty-development.net/aB9NKE
在 XSLT 1.0 中,不支持 ends-with()
函数,您需要执行如下操作:
<xsl:template match="*[substring(namespace-uri(), string-length(namespace-uri()) - 16) = '/AAA/services/Bar']">