1
0
mirror of https://github.com/alexandrev/xslt-lab.git synced 2026-09-18 19:43:16 +00:00
Files
xslt-lab/site/content/xslt/functions/xpath-qname.md
T
alexandrev-tibco 53e90ef86e feat(blog): complete XSLT/XPath reference — 229 function pages
Full coverage of XSLT 1.0, 2.0 and 3.0 elements and XPath functions:
- 59 XSLT elements (xsl:stylesheet → xsl:use-accumulators)
- 170 XPath functions (1.0 node/string/numeric/boolean, 2.0 sequence/
  date/QName/string, 3.0 HOF/map/array/JSON/streaming)
Each page: description, parameters table, return value, 2 runnable
Saxon examples with input XML + stylesheet + output, notes, cross-links.
xsltCompletions.js: all 229 entries now have blogSlug for hover links.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 09:28:05 +02:00

3.3 KiB

title, description, date, version, versionLabel, category, syntax, tags
title description date version versionLabel category syntax tags
QName() Constructs an xs:QName value from a namespace URI and a lexical qualified name string. 2026-04-18T00:00:00Z 2.0 XSLT 2.0 QName function QName(namespace-uri, lexical-qname)
xslt
reference
xpath
xslt2

Description

QName() creates an xs:QName value by combining a namespace URI string with a lexical qualified name (which may include a prefix). This is the primary way to construct typed QName values dynamically in XPath 2.0.

The resulting xs:QName can be used for namespace-aware name comparisons, passed to functions like node-name(), and used with element-available() or type-available().

Parameters

Parameter Type Required Description
namespace-uri xs:string? Yes The namespace URI. Pass an empty string "" for no namespace.
lexical-qname xs:string Yes A lexical qualified name, optionally including a prefix (e.g., "xs:date" or "item").

Return value

xs:QName — the constructed QName with the given namespace URI, local name, and prefix.

Examples

Compare a node's name to a constructed QName

Input XML:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:app="http://example.com/app">
  <app:widget type="button">Click me</app:widget>
  <app:widget type="text">Enter value</app:widget>
  <other:item xmlns:other="http://example.com/other">Extra</other:item>
</root>

Stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/root">
    <widgets>
      <xsl:copy-of select="*[node-name(.) eq QName('http://example.com/app', 'app:widget')]"/>
    </widgets>
  </xsl:template>
</xsl:stylesheet>

Output:

<widgets>
  <app:widget xmlns:app="http://example.com/app" type="button">Click me</app:widget>
  <app:widget xmlns:app="http://example.com/app" type="text">Enter value</app:widget>
</widgets>

Dynamically create an element with a qualified name

Stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/items/item">
    <xsl:variable name="qn" select="QName('http://example.com/out', concat('out:', @type))"/>
    <xsl:element name="{local-name-from-QName($qn)}"
                 namespace="{namespace-uri-from-QName($qn)}">
      <xsl:value-of select="."/>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

Notes

  • The prefix in the lexical-qname argument is stored in the xs:QName value but has no significance beyond readability — namespace-aware comparison uses the namespace URI and local name only.
  • If namespace-uri is empty ("") and the lexical name contains a colon, an error is raised.
  • QName() is the typed-value complement of resolve-QName(), which resolves namespace prefixes from an element's in-scope namespaces.

See also