XSLT: Add namespace to root element

Posted by Ingrid on Stack Overflow See other posts from Stack Overflow or by Ingrid
Published on 2010-04-21T21:19:53Z Indexed on 2010/04/21 21:23 UTC
Read the original article Hit count: 246

Filed under:
|
|

I need to change namespaces in the root element as follows:

input document:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<foo 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">

desired output:

<foo audience="external" xsi:schemaLocation="urn:isbn:1-931666-22-9     http://www.loc.gov/ead/ead.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="urn:isbn:1-931666-22-9">

I was trying to do it as I copy over the whole document and before I give any other transformation instructions, but the following doesn't work:

<xsl:template match="* | processing-instruction() | comment()">
    <xsl:copy copy-namespaces="no">
        <xsl:for-each select=".">
            <xsl:attribute name="audience" select="'external'"/>
            <xsl:namespace name="xlink" select="'http://www.w3.org/1999/xlink'"/>
        </xsl:for-each>
        <xsl:apply-templates/>
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

Thanks for any advice!

© Stack Overflow or respective owner

Related posts about xsl

Related posts about root