[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Global namespace prefixes (Corrected Examples)

Subject: Global namespace prefixes (Corrected Examples)
From: Nathan Potter <ndp@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 13 Nov 2008 15:20:54 -0800
 Global namespace prefixes (Corrected Examples)
(I post this earlier and bungled it. My examples where broken, and I managed to attach it to an existing thread. Here's a better effort.)


The crux of my question is this:

Is there a way to get namespace prefix declarations into the root element of the result tree through the XSLT API? Or must each namespace prefix declared in the root element of the result tree be present in the xsl:stylesheet element of the transform?

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.


<?xml version="1.0" encoding="UTF-8"?>
<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>


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

   <xsl:template match="dap:Dataset" >
            <xsl:apply-templates />

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


And it works. Output:

<?xml version="1.0" encoding="UTF-8"?>
<output xmlns:dap="http://xml.opendap.org/ns/DAP/3.2#">
<ns0:Conventions xmlns:ns0="http://base.document/att#">CF-1.0</ ns0:Conventions>
<ns1:logname xmlns:ns1="http://base.document/att#">olson</ ns1:logname>
<ns2:host xmlns:ns2="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 (I end up with hundreds of these prefixes).

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


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.