As a follow-up to my previous message, I meant to also include that the style sheet example that you shared didn't fail because of XPath statements, but because of the fact that you were using <xsl:copy-of> to copy everything over, including the namespace.
As described here, http://www.w3schools.com/xsl/el_copy-of.asp, <xsl:copy-of> creates a complete copy of the current node (and you can't get rid of its namespace nodes just by trying to strip the declaration from the EAD element like that). Also, it's in the "xsl" namespace, so namespaces really aren't that scary! :)
If you get into more complicated uses of XSL, though, I'd definitely recommend checking out the XSL-List, http://www.mulberrytech.com/xsl/xsl-list/. The regulars on that listserv know XSL exceptionally well, and they often come up with very creative and terse solutions.
Mark Custer
-----Original Message-----
From: Encoded Archival Description List [mailto:[log in to unmask]] On Behalf Of Eric Lease Morgan
Sent: Tuesday, April 03, 2012 4:18 PM
To: [log in to unmask]
Subject: duplicate an xml file
Using XSLT, how can I duplicate an XML file sans namespaces?
I have a set of valid DTD-based EAD files that I transform into HTML using a XSL stylesheet. Tastes great and less filling.
I now have a set of valid schema-based EAD files but I can't transform them because namespaces get in the way.
My tentative solution to this problem is to copy the schema-based EAD file to new XML file sans the name spaces, and then transform the result, but my XPath statements are incorrect. This way I can use a single XSL stylesheet for HTML creation.
Here is a schema-based EAD snippet:
<?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><!-- cool stuff here --></eadheader>
<archdesc level="collection"><!-- more cool stuff here --></archdesc>
</ead>
Here is a stylesheet:
<?xml version='1.0'?>
<xsl:stylesheet
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version='1.0'>
<xsl:template match="/">
<ead>
<xsl:copy-of select="/ead/eadheader"/>
<xsl:copy-of select="/ead/archdesc"/>
</ead>
</xsl:template>
</xsl:stylesheet>
The stylesheet works great if I remove all the name spaces from the EAD, but I can't do that because that is the whole point of the transformation. What sort of XPath statements do I need in order successful do the copy-of command?
--
Eric Lease Morgan
University of Notre Dame
|