Subject: Re: [xsl] Namespace handling question From: David Carlisle <davidc@xxxxxxxxx> Date: Fri, 14 May 2010 20:13:22 +0100 |
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=".">
You only need xsl;element and xsl:namespace if these are going to use values dynnamically generated at run time.<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:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" >
$ saxon9 ns1.xml ns1.xsl <?xml version="1.0" encoding="UTF-8"?> <oai_dc:dc xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/"
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>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Namespace handling question, Bridger Dyson-Smith | Thread | Re: [xsl] Namespace handling questi, Bridger Dyson-Smith |
[xsl] Namespace handling question, Bridger Dyson-Smith | Date | [xsl] Cannot use a parameter value , Peter Desjardins |
Month |