What is the difference between name () and local-name ()?

I do not understand the difference between XPath name and local-name functions.

Could you give an example of a situation in which they will differ?

Edit

In this example:

 <?xml version="1.0" ?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head></head> </html> 

I get the same result with these two queries: //*[local-name()="head"] and //*[name()="head"] . Why is this?

+44
xml xpath
Mar 17
source share
1 answer

When using XML

 <x:html xmlns:x="http://www.w3.org/1999/xhtml"/> 

style sheet

 <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> 

exits

 <local-name>html</local-name> <name>x:html</name> 

Thus, the result of local-name() does not have a prefix, the result of the name() may contain a prefix.

In your example with a default namespace declaration, the prefix is ​​missing, so name() and local-name() give the same result.

+58
Mar 17 '10 at 18:36
source share



All Articles