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

Setting the namespace in a document root element

Subject: Setting the namespace in a document root element
From: Michael Burek <mburek@xxxxxxxx>
Date: Wed, 18 Oct 2006 19:39:31 -0600
gmd.xsd
I have a question that has been puzzling me and some of my colleagues. I've spent some time searching FAQs etc, but
haven't found this variant. If the answer can be found in an FAQ or mailing list somewhere a pointer would be appreciated. I haven't found the right jumble of search words to get me to information I need.


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)

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

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.