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

Re: Global namespace prefixes (Corrected Examples)

Subject: Re: Global namespace prefixes (Corrected Examples)
From: Nathan Potter <ndp@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 14 Nov 2008 14:38:56 -0800
Re:  Global namespace prefixes (Corrected Examples)
Oddly, When I run the stylesheet (below), against the data (below) I get:

<?xml version="1.0" encoding="UTF-8"?>
<output xmlns:dap="http://xml.opendap.org/ns/DAP/3.2#" xmlns:ns0="http://base.document " ns0:ns="http://base.document">
<base:Conventions xmlns:base="http://base.document">CF-1.0</ base:Conventions>
<base:logname xmlns:base="http://base.document">olson</base:logname>
<base:host xmlns:base="http://base.document">bb0001en</base:host>
</output>



It just ignores the prefix when the attribute is added to the output element.





Nathan








On Nov 14, 2008, at 12:16 PM, Wendell Piez wrote:

Hi,

Here's a different approach. I don't know if the requirements allow it, but basically the idea is to create a dummy attribute in the new namespace on the document element, where the namespace will then be declared, leaving it in scope lower down, and thereby relieving the need to declare it for each of the lower-level elements.

So

<xsl:stylesheet
 xmlns:dap="http://xml.opendap.org/ns/DAP/3.2#"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

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

<xsl:variable name="ns" select="/dap:Dataset/@base"/>

<xsl:variable name="prefix" select="'base'"/>

  <xsl:template match="dap:Dataset" >
       <output>
         <xsl:attribute name="{$prefix}:ns" namespace="{$ns}">
           <xsl:value-of select="$ns"/>
         </xsl:attribute>
           <xsl:apply-templates />
       </output>
  </xsl:template>

  <xsl:template match="dap:Attribute" >
      <xsl:element name="{$prefix}:{@name}" namespace="{$ns}">
        <xsl:value-of select="." />
      </xsl:element>
  </xsl:template>

</xsl:stylesheet>

On the data

<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>
</Dataset>


using Xalan, I get

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


Yes, there's a bit of scat there; I don't know if that presents a problem. But no XSLT extension, and hence no extension namespace, is required.

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
 Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


============================================================ 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.