Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

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

Question posted by: Riaan (Guest) on June 27th, 2008 07:07 PM
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
Join Bytes!
Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
June 27th, 2008
07:07 PM
#2

Re: How to: Transform a XML structure to a string element value
Riaan wrote:
Quote:
What XSLT can I use to give me my required result??


Either use an extension function like saxon:serialize
http://www.saxonica.com/documentati.../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/

 
Not the answer you were looking for? Post your question . . .
189,876 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors