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

Discussion in 'XML' started by Riaan, Jun 10, 2008.

  1. Riaan

    Riaan Guest

    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
    Riaan, Jun 10, 2008
    #1
    1. Advertising

  2. 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/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.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jun 10, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KathyB
    Replies:
    0
    Views:
    968
    KathyB
    Jun 24, 2003
  2. chris yoker
    Replies:
    3
    Views:
    378
    chris yoker
    Jan 18, 2005
  3. Leo Nunez
    Replies:
    3
    Views:
    1,212
    Neil Kurzman
    Feb 9, 2005
  4. Joe Fawcett
    Replies:
    0
    Views:
    362
    Joe Fawcett
    Nov 21, 2007
  5. HANM
    Replies:
    2
    Views:
    708
    Joseph Kesselman
    Jan 29, 2008
Loading...

Share This Page