xsl-list
[Top] [All Lists]

[xsl] Losing a namespace declaration while merging two elements

2011-07-22 09:53:28
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>