xsl-list
[Top] [All Lists]

[xsl] How to take a QName value and make it an attribute?

2012-08-01 10:24:52
Hi Folks,

I want to transform the <fault> element in this document:

<Test xmlns:soap="http://www.soap.org";>
    <fault>soap:client</fault>
</Test>

Note that the value of the <fault> element is 

    soap:client

which is a QName.

I want to transform the <fault> element to this:

    <fault soap:client="blah">soap:client</fault>

That is, make the QName value an attribute and assign it the string "blah."

After transformation the XML document is to be this:

<Test xmlns:soap="http://www.soap.org";>
    <fault soap:client="blah">soap:client</fault>
</Test>

I tried this code:

    <xsl:template match="fault">
        <xsl:copy>
            <xsl:variable name="QName" select="." />
            <xsl:attribute name="{$QName}">blah</xsl:attribute>
            <xsl:value-of select="." />
        </xsl:copy>
    </xsl:template>

But it produces this error message:

    Undeclared prefix in attribute name: soap

What is the proper way to accomplish the desired transformation please?

/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>
--~--