Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: Cannot add XHTML data content to a page in XSLT

$
0
0
I have an XHTML field attached via a DataReference to another datatype, but cannot output it onto a page as unescaped HTML code. It either comes in escaped, or as an attribute to the containing DIV block.

My XML results:
<in:inputs xmlns:in="http://www.composite.net/ns/transformation/input/1.0">
    <in:result name="GetDataXml">
        <Data Id="3151c798-8c43-4834-bcbd-f1a47035f0e8" SubData.Body="&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt;&lt;/body&gt; &lt;/html&gt;" xmlns=""/>
    </in:result>
</in:inputs>
My XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:in="http://www.composite.net/ns/transformation/input/1.0"
                xmlns:lang="http://www.composite.net/ns/localization/1.0"
                xmlns:f="http://www.composite.net/ns/function/1.0"
                xmlns="http://www.w3.org/1999/xhtml"
                exclude-result-prefixes="xsl in lang f">
    <xsl:variable name="data" select="/in:inputs/in:result[@name='GetDataXml']" />
    <xsl:template match="/">
        <html>
            <head />
            <body>
                <xsl:choose>
                    <xsl:when test="count($data/Data) = 1">
                        <xsl:apply-templates select="$data/Data" />
                    </xsl:when>
                    <xsl:otherwise>
                        <p>Zero or more than 1 results</p>
                    </xsl:otherwise>
                </xsl:choose>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="*">
        <h2>Body:</h2>
        <xsl:choose>
            <xsl:when test="@SubData.Body != ''">
                <xsl:copy-of select="@SubData.Body"/>
            </xsl:when>
            <xsl:otherwise>
                <p>Nothing to display</p>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
This gives me an error of:
XslTransformException: Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added.
If I use:
<div><xsl:copy-of select="@SubData.Body"/></div>
... instead, I get an output of:
<div SubData.Body="&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt;&lt;/body&gt; &lt;/html&gt;"/>
I've also tried using <xsl:value-of select="@SubData.Body" disable-output-escaping="yes" />, but that doesn't work either.

What am I doing wrong?

Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>