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

Namespace handling question

Subject: Namespace handling question
From: Bridger Dyson-Smith <bdysonsmith@xxxxxxxxx>
Date: Fri, 14 May 2010 14:36:06 -0400
 Namespace handling question
All -
thanks for reading. I'm trying to generate OAI records for a series of
XML files; while I have the bulk of the processing working, I'm stuck
on a namespaces issue. I understand how to include/add a namespace to
my output file, I'm curious if there's a way to keep all of the
namespace information in the XML header - primarily to keep things
tidy. I've found a short XSL from Michael Kay on the dpawson website
for cleaning up the XML after the initial transform and I've
incorporated that as a second step in the process. Is there a good way
to combine the two?

And a second, related question: there is an xsi:schemaLocation that I
apparently need to include in the XML header. Attempts at using
<xsl:import-schema> and <xsl:namespace> haven't yielded correct
results. Would someone be willing to recommend a method for this? (See
the final example for my goal output).

I'm using XLST 2.0 and the Saxon-HE 9.2.0.6 in the oXygen editor.

Again, many thanks. Please excuse me if this has been beaten to death
- web searches and the list archives have so far refused to answer
this.
Best,
Bridger

My original XML looks something like this:
<root>
	<row>
		<title>Mice</title>
		<author>Kat, Krazy</author>
		<subject>bricks</subject>
		<number>01101100011011110111011001100101</number>
	</row>	
</root>

And I'm processing with the following XSL:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0" xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <xsl:output method="xml" media-type="text/xml" indent="yes"/>


    <xsl:template match="/">
        <xsl:apply-templates />
    </xsl:template>

    <xsl:template match="row">
        <xsl:for-each select=".">
            <xsl:result-document href="{concat(child::title,
child::number, '.xml')}">
                <xsl:element name="oai_dc:dc">
                    <xsl:namespace name="oai_dc"
select="'http://www.openarchives.org/OAI/2.0/oai_dc/'"/>
                    <xsl:namespace name="xsi"
select="'http://www.w3.org/2001/XMLSchema-instance'"/>
                    <xsl:element name="dc:publisher">Ignatz Mouse
Publishers</xsl:element>
                    <xsl:element name="dc:creator"><xsl:value-of
select="child::author"/></xsl:element>
                    <xsl:element name="dc:title"><xsl:value-of
select="child::title"/></xsl:element>
                    <xsl:element name="dc:subject"><xsl:value-of
select="child::subject"/></xsl:element>
                    <xsl:element name="dc:identifier"><xsl:value-of
select="child::number"/></xsl:element>
                </xsl:element>
            </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Currently my results look like this:
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <dc:publisher xmlns:dc="http://purl.org/dc/elements/1.1/">Ignatz
Mouse Publishers</dc:publisher>
   <dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Kat,
Krazy</dc:creator>
   <dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">Mice</dc:title>
   <dc:subject xmlns:dc="http://purl.org/dc/elements/1.1/">bricks</dc:subject>
   <dc:identifier
xmlns:dc="http://purl.org/dc/elements/1.1/">01101100011011110111011001100101</dc:identifier>
</oai_dc:dc>

where I like to get results closer to this:
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
   <dc:publisher>Ignatz Mouse Publishers</dc:publisher>
   <dc:creator>Kat, Krazy</dc:creator>
   <dc:title>Mice</dc:title>
   <dc:subject>bricks</dc:subject>
   <dc:identifier>01101100011011110111011001100101</dc:identifier>
</oai_dc:dc>
I arrived here by using my XSLT, Michael's cleaning XSLT, and then a
find/replace in the files.

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.