XSLT <xsl:namespace-alias> element

Definition and usage

<xsl:namespace-alias> element is used to replace the namespace in the stylesheet with a different namespace in the output, in other words, using other prefixes to replace the prefixes associated with the given namespace.

Note:<xsl:namespace-alias> is a top-level element (top-level element) and must be a child element of <xsl:stylesheet> or <xsl:transform>.

Sometimes, an XSLT file generates another XSLT. This brings a problem with namespaces, because there is no clear way to declare two prefixes for the same namespace, and the processor will not treat the two prefixes as the same namespace and operate on them. The <xsl:namespace-alias> command can allocate a transitional namespace to an alternative prefix, apply the stylesheet, and then map the alternative namespace to the XSLT namespace.

Although the generation of files from XSL to XSL is the main purpose of this command, it is not the only purpose. This command can be used in any namespace conflict (for example, xsi: schema data type namespace).

syntax

<xsl:namespace-alias
stylesheet-prefix="prefix|#default"
result-prefix="prefix|"#default"/>

attribute

attribute value description
stylesheet-prefix
  • prefix
  • #default
Απαιτείται. Ορίζει τον ονομαστό χώρο που θέλετε να αλλάξετε.
result-prefix
  • prefix
  • #default
Απαιτείται. Ορίζει τον προσδοκώμενο ονομαστό χώρο για την έξοδο.

Παράδειγμα

Παράδειγμα 1

Ο πρόθεμα wxsl μετατρέπεται στον πρόθεμα xsl: στον έξοδο:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wxsl="http://www.codew3c.com/w3style.xsl"
<xsl:namespace-alias stylesheet-prefix="wxsl" result-prefix="xsl"/>
<xsl:template match="/">
  <wxsl:stylesheet>
    <xsl:apply-templates/>
  </wxsl:stylesheet>
</xsl:template>
</xsl:stylesheet>