使用XSLT/XPath,如何匹配空名称空间中的任何元素?

时间:2020-12-30 19:24:22
<xsl:template match="foo">

matches the foo element in the null namespace.

匹配null名称空间中的foo元素。

<xsl:template match="*">

matches any element in any namespace.

匹配任何名称空间中的任何元素。

I tried:

我试着:

xmlns:null=""
...
<xsl:template match="null:*">

but it's illegal to declare a prefix for the null namespace.

但是为空名称空间声明前缀是非法的。

So how can I match an element with any name in the null namespace?

那么,如何将元素与空名称空间中的任何名称匹配?

2 个解决方案

#1


5  

You could try:

你可以试试:

<xsl:template match='*[namespace-uri() = ""]'>

If the node-set is empty or has no namespace URI, an empty string is returned by the namespace-uri function, which should achieve what you want.

如果节点集是空的,或者没有名称空间URI,名称空间- URI函数将返回一个空字符串,该函数将实现您想要的。

#2


4  

ffpf is correct.

ffpf是正确的。

For even more clarity I would recommend to use the following match pattern:

为了更加清晰,我建议使用以下匹配模式:

 '*[not(namespace-uri() )]'

‘*[不是(名称空间uri()))”

#1


5  

You could try:

你可以试试:

<xsl:template match='*[namespace-uri() = ""]'>

If the node-set is empty or has no namespace URI, an empty string is returned by the namespace-uri function, which should achieve what you want.

如果节点集是空的,或者没有名称空间URI,名称空间- URI函数将返回一个空字符串,该函数将实现您想要的。

#2


4  

ffpf is correct.

ffpf是正确的。

For even more clarity I would recommend to use the following match pattern:

为了更加清晰,我建议使用以下匹配模式:

 '*[not(namespace-uri() )]'

‘*[不是(名称空间uri()))”