Subject: Re: [xsl] Global namespace prefixes (Corrected Examples) From: Nathan Potter <ndp@xxxxxxxxxxxxxxxxxxxx> Date: Thu, 13 Nov 2008 15:41:01 -0800 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Global namespace prefixes, David Carlisle | Thread | Re: [xsl] Global namespace prefixes, David Carlisle |
Re: [xsl] Global namespace prefixes, David Carlisle | Date | Re: [xsl] Global namespace prefixes, Nathan Potter |
Month |