[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: Setting the namespace in a document root element
Subject: Re: Setting the namespace in a document root element
From: Michael Burek <mburek@xxxxxxxx>
Date: Thu, 19 Oct 2006 10:40:18 -0600
|
Abel, Michael,
Thanks for the quick responses about this. I was able to get this to
give the result I want by using "Saxon 8B", which came with the
distribution of the oXygen editor that I'm using and using the
Literal Result Element approach. The Saxon library I have looks to
be a slightly older version of the 8.x series (Jar contents are dated
Wed Apr 12 18:00:38 MDT 2006)
The xsl:namespace element approach did not work correctly in the
saxon version that I have.
I have the possibility of using Xalan (version unknown) and Saxon
6.5.5, neither produced the correct result with either the LRE or the
namespace element.
For the record, I'm working on a Powerbook G4, which may be biasing
the results.
If I can supply any other specific information that would be helpful,
let me know.
Again, thanks.
Michael
On Oct 19, 2006, at 3:26 AM, Michael Kay wrote:
In the output document below I want the xmlns:gco="http://
www.isotc211.org/2005/gco namespace declaration to appear in
the MD_Metadata root element, not in the CharacterString
child element(s)
As it happens this came up in another thread yesterday. The simple
answer is
to use literal result elements rather than xsl:element. LRE's copy all
in-scope namespaces from the stylesheet (unless excluded using
exclude-result-prefixes), xsl:element doesn't. In any case, LRE's
in my view
are easier to write and easier to read.
So change:
<xsl:element name="MD_Metadata" >
to:
<MD_Metadata xmlns:gco="http://www.isotc211.org/2005/gco">
This then raises the question of why your <xsl:namespace>
instruction didn't
do the trick. It ought to, and the output I get from Saxon 8.8 in fact
matches your desired output.
Michael Kay
http://www.saxonica.com/
Input file:
<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns="http://www.unidata.ucar.edu/namespaces/thredds/
InvCatalog/v1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http:// www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.unidata.ucar.edu/namespaces/
thredds/InvCatalog/v1.0
http://www.unidata.ucar.edu/schemas/thredds/InvCatalog.
1.0.xsd">
<dataset ID="ucar.scd.vets.vg.cat" name="Meteorology
Navigation and Surface State Parameters" harvest="true">
<date type="metadataHarvested" format="YYYY-MM-
DD">2006-08-26</date>
</dataset>
</catalog>
Style sheet:
?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns="http://www.isotc211.org/2005/
gmd"
xmlns:gco="http://www.isotc211.org/2005/gco"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:thredds="http://www.unidata.ucar.edu/namespaces/
thredds/
InvCatalog/v1.0"
xsi:schemaLocation="http://www.isotc211.org/2005/gmd
../2005/ gmd/gmd.xsd http://www.isotc211.org/2005/gco ../gco/gco.xsd"
exclude-result-prefixes="thredds" >
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="thredds:catalog">
<xsl:element name="MD_Metadata" >
<xsl:namespace name="gco">http://www.isotc211.org/2005/
gco</xsl:namespace>
<xsl:attribute name="xsi:schemaLocation">
http://www.isotc211.org/2005/gmd
../gmd/gmd.xsd http://www.isotc211.org/2005/gco ../gco/gco.xsd
</xsl:attribute>
<xsl:variable name="datasetId"
select="thredds:dataset/ @ID"/>
<!-- fileIdentifier -->
<xsl:element name="fileIdentifier">
<xsl:element name="gco:CharacterString">
<xsl:value-of select="$datasetId"/>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Output: (edited to add spaces and CRs for clarity)
<?xml version="1.0" encoding="UTF-8"?>
<MD_Metadata xmlns="http://www.isotc211.org/2005/gmd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.isotc211.org/2005/gmd
../gmd/gmd.xsd http://www.isotc211.org/2005/gco../gco/ gco.xsd">
<fileIdentifier>
<gco:CharacterString xmlns:gco="http://www.isotc211.org/
2005/
gco">ucar.scd.vets.vg.cat</gco:CharacterString>
</fileIdentifier>
</MD_Metadata>
Desired Output:
<?xml version="1.0" encoding="UTF-8"?>
<MD_Metadata xmlns="http://www.isotc211.org/2005/gmd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
xmlns:gco="http://www.isotc211.org/2005/gco
xsi:schemaLocation="http://www.isotc211.org/2005/gmd
../gmd/ gmd.xsd
http://www.isotc211.org/2005/gco ../gco/ gco.xsd" >
<fileIdentifier>
<gco:CharacterString">ucar.scd.vets.vg.cat</gco:CharacterString>
</fileIdentifier>
</MD_Metadata>
There are many CharacterString and other gco namespace
elements in the real output document, so having the namespace
in each is undesirable.
Thanks in advance,
Michael
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|