[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"
version="1.0">
	...
	</xsl:stylesheet>

You can use an XPath axis like so:

	namespace::*

In XSLT it could look something like this:

	<xsl:template match="/xsl:stylesheet">
		<xsl:for-each select="namespace::*">
			<p>
				Prefix: <xsl:value-of
select="{local-name()}"/>
				<br/>
				URI: <xsl:value-of select="{.}"/>
			</p>
		</xsl:for-each>
	</xsl:template>
</tip>


More information about the thelist mailing list