Name
[2.0] <xsl:namespace>
Allows you to create a namespace node in the result tree.
Category
Instruction.
Required Attribute
nameThe namespace prefix.
Optional Attribute
selectAn XPath expression that defines the value of the namespace itself. If you don’t use the
selectattribute, the<xsl:namespace>element must contain content.
Content
The <xsl:namespace>
element must have content or a select attribute; it is an error if it has
both or neither. It is also an error if the <xsl:namespace> element evaluates to a
zero-length string.
Appears in
<xsl:namespace> appears
inside a template.
Defined in
[2.0] XSLT section 11.7, “Creating Namespace Nodes.”
Example
Courtesy of the XSLT 2.0 spec, here is a stylesheet with a
literal result element that contains an <xsl:namespace> element:
<?xml version="1.0"?> <!-- namespace.xsl --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <data xsi:type="xs:integer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xsl:namespace name="xs" select="'http://www.w3.org/2001/XMLSchema'"/> <xsl:text>42</xsl:text> </data> </xsl:template> </xsl:stylesheet>
Notice that the value of the select attribute is in single quotes inside
double quotes; without the single quotes, this would select any
<http://www.w3.org/2001/XMLSchema>
elements, causing an error.
The results of this stylesheet look like this:
<?xml version="1.0" encoding="UTF-8"?> <data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access