[xsl] Global namespace prefixes

Subject: [xsl] Global namespace prefixes
From: Nathan Potter <ndp@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 13 Nov 2008 13:45:14 -0800

I have the situation that I need to use (create elements in) a namespace whose name is contained in, but not a declared namespace of, the input document for my XSLT.


<Dataset xmlns="http://xml.opendap.org/ns/DAP/3.2#"; base="http://base.document ">
<Attribute name="Conventions" >CF-1.0</Attribute>
<Attribute name="logname" />olson</Attribute>
<Attribute name="host" />bb0001en</Attribute>


<xsl:stylesheet version="1.0"
<xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes'/>

<xsl:template match="dap:Attribute" mode="body" >
<xsl:element name="{@name}" namespace="{/dap:Dataset/@base}/ att#"><xsl:value-of>.</xsl:value-of></xsl:element>


And this works:

<ns0:Conventions xmlns:ns131="http://base.document/att#";>CF-1.0</ ns0:Conventions>
<ns1:logname xmlns:ns132="http://base.document/att#";>olson</ ns1:logname>
<ns2:host xmlns:ns133="http://base.document/att#";>bb0001en</ ns2:host>

However this bit of creating a new prefix for every element - even though the namespace is the same - is a bit of a drag from a readability standpoint. From what I can tell the only way to get a single, global, namespace prefix into the result tree is for it to be declared in the xsl:stylesheet element of the transform.

Is that true?

If so then I think that means I need to modify the xsl:stylesheet document for each document processed.
Is that a reasonable design pattern?


============================================================ Nathan Potter Oregon State University, COAS ndp at coas.oregonstate.edu 104 Ocean. Admin. Bldg. 541 737 2293 voice Corvallis, OR 97331-5503 541 737 2064 fax

Current Thread