468,256 Members | 1,435 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,256 developers. It's quick & easy.

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

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
RG****@silica.net
Jun 27 '08 #1
1 1398
Riaan wrote:
What XSLT can I use to give me my required result??
Either use an extension function like saxon:serialize
http://www.saxonica.com/documentatio...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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ravi | last post: by
6 posts views Thread by Stephen Cook | last post: by
6 posts views Thread by tcdevelopment | last post: by
6 posts views Thread by Laurent | last post: by
4 posts views Thread by hawat.thufir | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.