xsl-list
[Top] [All Lists]

RE: Transform XML into CDATA

2006-02-14 09:05:29
is this you wanted to see ??

<IMAGE>
        <NAME>picture.jpg</NAME>
        <CAPTION>
      <![CDATA[Image info goes here<BR>Here is the comment<BR/>
                <a href="picture.jpg" target="_blank" />
                <U>Open image in new window</U>
       ]]>
        </CAPTION>
</IMAGE>


because you have given the cdata-section-elements="CAPTION" all the text-only nodes under the caption node will be in the CDATA section.And so any other nodes are ever considered as CDATA, unless you actually make them CDATA (making them just any other text )
example:
<xsl:text disable-output-escaping="yes"><![CDATA[<a href = "]]></xsl:text>

Try this.,.

<xsl:template match="record" mode = "image">
                <xsl:element name="IMAGE">
                        <NAME>
                                <xsl:value-of select="item[1]"/>
                        </NAME>
                        <CAPTION>
                                <xsl:value-of select="item[2]"/>
                                <xsl:if test="normalize-space(item[3])">
                                        <xsl:text 
disable-output-escaping="yes"><![CDATA[<br/>]]></xsl:text>
                                        <xsl:value-of select="item[3]"/>
                                </xsl:if>
<xsl:text disable-output-escaping="yes"><![CDATA[<br/><a href = "]]></xsl:text>
                                <xsl:value-of select = "item[1]"/>
                                <xsl:text disable-output-escaping="yes">
<![CDATA[" target="_blank"/><U>Open image in new window</U>]]></xsl:text>
                        </CAPTION>
                </xsl:element>
        </xsl:template>

I have also changed the code a bit , where i thought could be changed.

HTH
Vasu

From: Verakso <verakso(_at_)gmail(_dot_)com>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Transform XML into CDATA
Date: Tue, 14 Feb 2006 16:25:07 +0100

I have some problems getting this right.

In a FlashViewer, I need to feed some xml data, however some of the
data needs to be in a CDATA section, like:

<IMAGE>
        <NAME>pictue.jpg</NAME>
        <CAPTION><![CDATA[Image info goes here.<BR>Here is the comment<BR><A
href="images/picture.jpg" target="_blank">
<U>Open image in new window</U></A>]]></CAPTION>
</IMAGE>

The original data is in xml like:
<record>
        <item name="File">picture.jpg</item>
        <item name="Desc">Image info goes here</item>
        <item name="Comment">Here is the comment</item>
</record>

Now, I have been trying to accomplish this be searching the archives
on this list, and came up with some xlt that uses
cdata-section-elements="CAPTION" and looks like this.

<xsl:template match="record" mode="image">
        <xsl:element name="IMAGE">
                <xsl:element name="NAME">
                        <xsl:value-of select="item[1]"/>
                </xsl:element>
                <xsl:element name="CAPTION">
                        <xsl:value-of select="item[2]"/>
                        <xsl:if test="normalize-space(item[3])">
                                <xsl:value-of select="'&lt;BR&gt;'" 
disable-output-escaping="yes"/>
                                <xsl:value-of select="item[3]"/>
                        </xsl:if>
                        <xsl:value-of select="'&lt;BR&gt;'" 
disable-output-escaping="yes"/>
                        <xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="item[1]"/></xsl:attribute>
                                <xsl:attribute 
name="target">_blank</xsl:attribute>
                                <U>Open image in new window</U>
                        </xsl:element>
                </xsl:element>
        </xsl:element>
</xsl:template>

But this produces only a "half" CDATA section like this:
<IMAGE>
        <NAME>picture.jpg</NAME>
        <CAPTION><![CDATA[Image info goes here<BR>Here is the
comment<BR>]]><a href="picture.jpg" target="_blank">
                <U>Open image in new window</U>
                </a>
        </CAPTION>
</IMAGE>

How can I make all the data in the CAPTION element as CDATA?

/Thomas

BTW: The FlashViewer i am using is called SimpleViewer from
http://www.airtightinteractive.com/simpleviewer/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


_________________________________________________________________
Be the first to hear what's new at MSN - sign up to our free newsletters! http://www.msn.co.uk/newsletters


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>