How to: Transform a XML structure to a string element value

R

Riaan

As the subject suggests, I am trying to populate a element (of type
xs:string) with a entire XML structure from the source. The problem
is, I get the transformation to work... but the tranformation creates
the target element as a complex type, and not a xs:String type that I
require.

Example:
Source:
<test>
<msg>Hi</msg>
</test>

Required Destination:
<destination>
<value>
&lt;test&gt;
&lt;msg&gt;Hi&lt;/msg&gt;
&lt;/test&gt;
</value>
</destination>

I can only manage to produce this (which is incorrect):
<destination>
<value>
<test>
<msg>Hi</msg>
</test>
</value>
</destination>

What XSLT can I use to give me my required result??

Riaan Gouws
(e-mail address removed)
 
M

Martin Honnen

Riaan said:
What XSLT can I use to give me my required result??

Either use an extension function like saxon:serialize
http://www.saxonica.com/documentation/extensions/functions/serialize.html
or write templates that serialize your nodes yourself e.g. alike
<xsl:template match="*" mode="serialize">
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt;</xsl:text>
<xsl:apply-templates mode="serialize"/>
<xsl:text>&lt;/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt;</xsl:text>
</xsl:template>
The above is not a complete solution as it ignores attributes for instance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top