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

[xsl] Losing a namespace declaration while merging two elements


Subject: [xsl] Losing a namespace declaration while merging two elements
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Fri, 22 Jul 2011 10:53:12 -0400

Hi Folks,

I want to "merge" this:

<attribute ref="xlink:href" xmlns="http://www.w3.org/2001/XMLSchema"  />

with this:

<xsd:attribute name="href" type="xsd:anyURI"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"  />

to produce this:

<attribute name="href" type="xsd:anyURI"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" />

Notice that the value of @type is a QName ( xsd:anyURI ) so I need the
namespace declaration that has its prefix ( xsd ).

I wrote a function to do the merge:

    <xsl:function name="f:merge-ref-and-refed">
        <xsl:param name="ref-item" />
        <xsl:param name="refed-item" />

        <xsl:element name="{name($ref-item)}"
namespace="{namespace-uri($ref-item)}">
            <xsl:for-each select="$ref-item/@*[not(name() eq 'ref')]">
                <xsl:attribute name="{name(.)}"><xsl:sequence select="."
/></xsl:attribute>
            </xsl:for-each>
            <xsl:for-each select="$refed-item/@*">
                <xsl:attribute name="{name(.)}"><xsl:sequence select="."
/></xsl:attribute>
            </xsl:for-each>
            <xsl:sequence select="$refed-item/*" />
        </xsl:element>
    </xsl:function>

However, that produces this:

<attribute name="href" type="xsd:anyURI"
xmlns="http://www.w3.org/2001/XMLSchema"  />

It lost this important namespace declaration:

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

How do I fix my function so that it doesn't lose any namespace declarations?

/Roger


Current Thread
Keywords
xsd