[thelist] Another XSL question

David.Cantrell at Gunter.AF.mil David.Cantrell at Gunter.AF.mil
Thu Mar 13 09:37:45 CST 2003

> XSLT specification explicitly states that you cannot define 
> the namespace for your result tree using
> <xsl:attribute name="xmlns">
> So maybe the converse is true in that you can't access xmlns 
> as an attribute either.  This is all I can find right now I'm afraid.

Actually I figured this out yesterday evening, and sent in a tip but I guess
it got lost in the ether or maybe it bounced, so I'll resend.

It's actually embarrassingly easy... :)

<tip type="Referencing XML namespace attributes using XSLT and XPath"
author="Dave Cantrell">
If you want to access the namespace node of an element in an XML file, such
as the following:

	<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

You can use an XPath axis like so:


In XSLT it could look something like this:

	<xsl:template match="/xsl:stylesheet">
		<xsl:for-each select="namespace::*">
				Prefix: <xsl:value-of
				URI: <xsl:value-of select="{.}"/>

More information about the thelist mailing list