Hi all --
Many thanks for reading. I have a problem with running an identity transform on XML documents with namespaces. I can pre-process outside of XSLT and avoid the issue, but I'd like to be able to do this entirely inside XSLT 2.0.
Note: to simplify the examples, I've created XML documents that aren't schema-conformant. Avoid testing the transform in a schema-aware processor or you'll get errors!
Sample input (also available here:
http://pastebin.com/RFAQaY3w)
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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">
<eadheader findaidstatus="Ready_for_online" repositoryencoding="iso15511" countryencoding="iso3166-1" dateencoding="iso8601" langencoding="iso639-2b">
<eadid>01234</eadid>
<filedesc>
<AAA>1</AAA>
<BBB>2</BBB>
</filedesc>
</eadheader>
<archdesc>
<bib>
<CCC>1</CCC>
<DDD>2</DDD>
</bib>
</archdesc>
</ead>
Here is the XSLT:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0"
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">
<xsl:output method="xml" indent="yes" standalone="no"/>
<!-- The identity transform -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="filedesc">
<xsl:copy>
<header>Subjects</header>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Desired output:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<eadheader findaidstatus="Ready_for_online" repositoryencoding="iso15511" countryencoding="iso3166-1" dateencoding="iso8601" langencoding="iso639-2b">
<eadid>01234</eadid>
<filedesc>
<header>Subjects</header>
<AAA>1</AAA>
<BBB>2</BBB>
</filedesc>
</eadheader>
<archdesc>
<bib>
<CCC>1</CCC>
<DDD>2</DDD>
</bib>
</archdesc>
</ead>
Again, if I strip out all of the <ead> namespace values, the transform works. With the namespace values in the XSL, the transform reproduces an exact copy without the new <header> element.
Any advice is greatly appreciated. Thanks again for reading and your suggestions!