[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: Thu, 13 Nov 2008 15:41:01 -0800
Re:  Global namespace prefixes (Corrected Examples)
This is a much simplified example from a larger more complex situation.

I cannot solve this by making the namespace the default namespace.

On Nov 13, 2008, at 3:35 PM, David Carlisle wrote:



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



I'm surprised by those prefixes. An XSLT 1 processor is given a lot of
freedom to change prefixes at will, but most do not do so unless forced
to do so to avoid a namespace clash.


saxon6 (the old xslt 1 version of saxon)

produces


$ saxon mns.xml mns.xsl <?xml version="1.0" encoding="UTF-8"?> <output xmlns:dap="http://xml.opendap.org/ns/DAP/3.2#">

<Conventions xmlns="http://base.document/att#">CF-1.0</Conventions>

<logname xmlns="http://base.document/att#">olson</logname>

<host xmlns="http://base.document/att#">bb0001en</host>

</output>


In XSLT2 the system wuld have to generate unprefixed names in this context and saxon9 produes the same result:


$ saxon9 mns.xml mns.xsl Warning: at xsl:stylesheet on line 5 column 9 of mns.xsl: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor <?xml version="1.0" encoding="UTF-8"?> <output xmlns:dap="http://xml.opendap.org/ns/DAP/3.2#"> <Conventions xmlns="http://base.document/att#">CF-1.0</Conventions> <logname xmlns="http://base.document/att#">olson</logname> <host xmlns="http://base.document/att#">bb0001en</host> </output>


Note that while no prefixes are generated the namespace declaration does
appear multiple times as there is no parent element with the same
namespace. If the element <output> was placed in the namespace instead of
no-namespace then the namespace would only need to be declared once.



If I change the stylesheet to


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

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

<xsl:template match="dap:Dataset" >
<xsl:element name="output" namespace="{/dap:Dataset/@base}/ att#">
<xsl:apply-templates />
</xsl:element>
</xsl:template>


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


</xsl:stylesheet>

I get


$ saxon mns.xml mns.xsl <?xml version="1.0" encoding="UTF-8"?> <output xmlns="http://base.document/att#">

<Conventions>CF-1.0</Conventions>

<logname>olson</logname>

<host>bb0001en</host>

</output>


David


________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________


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