[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] XMLNS problem


Subject: [xsl] XMLNS problem
From: Eric Harbeson <kiteeatingtree@xxxxxxxxxxxxx>
Date: Tue, 12 Feb 2013 14:35:15 -0700

Dear all,

I have a namespace question I haven't been able to find an answer to, and none
of the similar questions I've found on this list so far have helped.  I've
never been able to get my head around namespaces, so if any of you can help,
I'd be appreciative.

I'm working on a project using Encoded Archival Description (EAD), and trying
to do minor adjustments to documents in order to make them compliant with a
different version of the schema.  I'm doing this by using XSLT to do a
complete copy of the input document, making changes to the output, but I can't
get the correct schema information to appear in the new document.

Here's what the input documents look like:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE ead PUBLIC "+//ISBN 1-931666-00-8//DTD ead.dtd (Encoded Archival
Description (EAD) Version 2002)//EN" "http://rmoa.unm.edu/dtd/ead.dtd">
<ead>
...
</ead>

In order for the output XML to be useful, heading needs to look like this:

<?xml version="1.0" encoding="UTF-8"?>
<ead
    xsi:schemaLocation="urn:isbn:1-931666-22-9
http://www.loc.gov/ead/ead.xsd"
    xmlns:ns2="http://www.w3.org/1999/xlink"
    xmlns="urn:isbn:1-931666-22-9"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...
</ead>

The best I've been able to come up with produces the following:

<?xml version="1.0" encoding="UTF-8"?>
<ead
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:isbn:1-931666-22-9&#xA;
http://www.loc.gov/ead/ead.xsd">
...
</ead>

This is close, but it doesn't include the xmlns line, which appears to be
needed for it to validate correctly. The XSLT I have below seems like it
should do what I want, but it produces an error in the xsl:namespace
declaration.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:input="urn:isbn:1-931555-22-9"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:ns2="http://www.w3.org/1999/xlink"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    exclude-result-prefixes="xs" version="2.0">
    <xsl:output method="xml"/>
    <xsl:strip-space elements="*"/>

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

    <xsl:template match="ead">
        <xsl:element name="ead">
            <xsl:namespace name="">urn:isbn:1-931666-22-9</xsl:namespace>
            <xsl:attribute name="xsi:schemaLocation">urn:isbn:1-931666-22-9
                http://www.loc.gov/ead/ead.xsd</xsl:attribute>
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>
...
</xsl:stylesheet>

Thanks in advance for any help you can provide!

All good wishes,
Eric


Current Thread
Keywords