[xsl] Adding an element of a specific type

Subject: [xsl] Adding an element of a specific type
From: "Hofman, Peter" <peter.hofman@xxxxxxxxxxxxx>
Date: Wed, 18 Oct 2006 15:47:27 +0200
Hi all,

How do I add an element of a specific type to the output.

This is my input:

<?xml version="1.0" encoding="UTF-8"?>
<ns1:P xmlns:ns1="somenamespace">
    <ns1:X>some data</ns1:X>
    <ns1:O>
        <ns1:C>
            ...
        </ns1:C>
    </ns1:O>
</ns1:P>

I want to get the structure below. The schema does not have element Q,
but only has complexType Q_Type:

<?xml version="1.0" encoding="UTF-8"?>
<ns1:Q type="ns1:Q_Type" xmlns:ns1="somenamespace">
    <ns1:C>
            ...
    </ns1:C>
</ns1:P>

I tried something like this, but that does not seem to work:

<xsl:template match="ns1:O">
    <xsl:element name="ns1:Q">
       <xsl:attribute name="xsi:type">ns1:Q_Type</xsl:attribute>
       <xsl:apply-templates select="ns1:C" >
    </xsl:element>
</xsl:template>

The processor starts complaining about the namespace of the type, which
I kind of expected already.
Haven't got a clue though how to fix this.

(sorry, but I am not sure which processor I have, since it is embedded
in an existing application)

Best regards,
Peter


This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be copied,
disclosed to, retained or used by, any other party. If you are not an intended
recipient then please promptly delete this e-mail and any attachment and all
copies and inform the sender. Thank you.

Current Thread