local-name

The local part of a node's name

Description

The fn:local-name function is useful only for element, attribute and processing instruction nodes. For an element or attribute, this is simply its name, stripped of any prefix it might have.

Parameters

Description

arg:node()

the node; if omitted, the context node

Examples

The examples below use this input document:

<xsl:stylesheet xmlns:pre="http://datypic.com/pre"
                xmlns:unpre="http://datypic.com/unpre">...

<xsl:variable name="in-xml" as="item()*">
  <noNamespace>
    <pre:prefixed xmlns="http://datypic.com/unpre"
             xmlns:pre="http://datypic.com/pre">
      <unprefixed pre:prefAttr="a" noNSAttr="b">123</unprefixed>
    </pre:prefixed>
  </noNamespace>
</xsl:variable>

XPath

Results

Explanation

local-name($in-xml)

noNamespace

local-name($in-xml//Q{http://datypic.com/pre}prefixed)

prefixed

In a generator the namespace prefixes are not declared, so the path uses Q{uri}name; *:name, which ignores the namespace, also works.

local-name($in-xml//Q{http://datypic.com/unpre}unprefixed)

unprefixed

In a generator the namespace prefixes are not declared, so the path uses Q{uri}name; *:name, which ignores the namespace, also works.

local-name($in-xml//@Q{http://datypic.com/pre}prefAttr)

prefAttr

In a generator the namespace prefixes are not declared, so the path uses Q{uri}name; *:name, which ignores the namespace, also works.

local-name($in-xml//@noNSAttr)

noNSAttr

In a generator

Copy the snippet below and paste it in Freemapper, under a language node inside the generators element. Each line of the pattern prints the result of one example; to see them, run mi generate <project> <language> example-local-name.

[e] example-local-name
    [e] vars
        [e] in-xml
            [e] select
                [v] copy-of(parse-xml('<noNamespace><pre:prefixed xmlns="http://datypic.com/unpre" xmlns:pre="http://datypic.com/pre"><unprefixed pre:prefAttr="a" noNSAttr="b">123</unprefixed></pre:prefixed></noNamespace>')/*)
    [e] start
        [e] match
            [v] /
        [e] body
            [e] write-pattern
                [v] examples
    [e] patterns
        [e] examples
            [v] E01: {{ local-name($in-xml) }}
            [v] E02: {{ local-name($in-xml//Q{http://datypic.com/pre}prefixed) }}
            [v] E03: {{ local-name($in-xml//Q{http://datypic.com/unpre}unprefixed) }}
            [v] E04: {{ local-name($in-xml//@Q{http://datypic.com/pre}prefAttr) }}
            [v] E05: {{ local-name($in-xml//@noNSAttr) }}

See Also