我真的不明白XPath函数name和local-name.
你能举例说明他们会有所不同吗?
鉴于这个例子:
<?xml version="1.0" ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head></head>
</html>
Run Code Online (Sandbox Code Playgroud)
我对这两个查询得到了相同的结果://*[local-name()="head"]和//*[name()="head"].这是为什么?
Mar*_*nen 74
随着XML的存在
<x:html xmlns:x="http://www.w3.org/1999/xhtml"/>
Run Code Online (Sandbox Code Playgroud)
样式表
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="*">
<local-name><xsl:value-of select="local-name()"/></local-name>
<name><xsl:value-of select="name()"/></name>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
输出
<local-name>html</local-name>
<name>x:html</name>
Run Code Online (Sandbox Code Playgroud)
因此local-name()结果是没有任何前缀,the name()结果可能包含前缀.
在一个默认的命名空间声明你的样品不存在任何前缀,因此name()并local-name()给出相同的结果.