Jyotsna Sonawane
Jyotsna Sonawane

Reputation: 303

XSLT: How to get XML

I have a XSL that transforms one format of XML into another. In input XML I have a node with following value - which is actually a XML string if we replace &lt; with < (less than) for e.g.

<otherInfo>&amp;lt;Paragraph&amp;gt;&amp;lt;Title&amp;gt;&amp;lt;!CDATA[Pour les nuits du 2012-10-01 - 2012-10-30]]&amp;gt;&amp;lt;/Title&amp;gt;&amp;lt;Text&amp;gt;&amp;lt;![CDATA[TAXES INCLUSES.]]&amp;gt;&amp;lt;/Text&amp;gt;&amp;lt;/Paragraph&amp;gt;</otherInfo>

I want to have the content of otherInfo as a XML node in output XML.

if I do xsl:valueof select="otherInfo", I do not get it as a XML node - it is output just as text. How can I make XSL output the content of otherInfo as XML node ?

Upvotes: 2

Views: 307

Answers (2)

user1745750
user1745750

Reputation:

If I understand you question correctly...

You could try something like this (code not tested)

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" version="1.0">

<xsl:template match="*">
    <xsl:variable name="xml-string">
    <Paragraph>
        <Title>
            <!CDATA[Pour les nuits du 2012-10-01 - 2012-10-30]]>
        </Title>
        <Text>
            <![CDATA[TAXES INCLUSES.]]>
        </Text>
    </Paragraph>
</xsl:variable>

    <xsl:variable name="xmlnode" select="exslt:node-set($xml-string)"/>

    Title is <xsl:value-of select="$xmlnode//Title"/>
</xsl:template>

Upvotes: 0

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243459

You either need to implement an XML parser written in XSLT, call an extension function, or wait for XSLT 3.0 where there may be a standard parse-xml() function.

Upvotes: 2

Related Questions