[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] CDATA question


Subject: RE: [xsl] CDATA question
From: "Uslu, Cihan Y (MED)" <Cihan.Uslu@xxxxxxxxxx>
Date: Thu, 15 Apr 2004 11:09:46 -0500

Thanks Ken, Michael, and David for the responses. It now works the way I
want it.

-----Original Message-----
From: G. Ken Holman [mailto:gkholman@xxxxxxxxxxxxxxxxxxxx]
Sent: Wednesday, April 14, 2004 4:36 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] CDATA question


At 2004-04-14 15:57 -0500, Uslu, Cihan Y (MED) wrote:
>I have the following XML structure, and the extract from the XSLT script
>which is not producing the desired output. What would be the best way to
>get desired output?

By building result text out of the input elements, not by building result 
nodes out of the input elements.

><xsl:....cdata-section-elements="mattext feedback">

This is a request only to put out text nodes in CDATA sections, it is not a 
request to emit the node tree syntax inside of a CDATA section as you
expected.

To get what you want you need to build your own text syntax from the input 
node structures and emit that as text, not as nodes.

A simple working example is below ... I hope this helps.

................. Ken

T:\ftemp>type uslu.xml
<tests>
   <assessment teds-type='T'>
     <distractor>
       <para>Select the<emphasis>GPO Part Additional Info</emphasis> link
       in the <emphasis>Navigation</emphasis> screen</para>
     </distractor>
   </assessment>
   <other>
     <para>Select the<emphasis>GPO Part Additional Info</emphasis> link
     in the <emphasis>Navigation</emphasis> screen</para>
   </other>
</tests>
T:\ftemp>type uslu.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version="1.0">

<xsl:output indent="yes" cdata-section-elements="mattext feedback"/>

<xsl:template match="distractor | answer">
  <xsl:choose>
  <xsl:when test="(ancestor::assessment[@teds-type = 'M']) or
(ancestor::assessment[@teds-type = 'T']) or
(ancestor::assessment[@teds-type = 'U'])">
  <response_label>
   <material>
    <mattext texttype="text/html">
      <xsl:apply-templates mode="syntax"/>
    </mattext>
   </material>
  </response_label>
  </xsl:when>
   </xsl:choose>
</xsl:template>

<xsl:template match="para" mode="syntax">
  <xsl:apply-templates mode="syntax"/>
</xsl:template>

<xsl:template match="emphasis" mode="syntax">
   <xsl:text/>&lt;b><xsl:apply-templates/>&lt;/b><xsl:text/>
</xsl:template>

<xsl:template match="@*|node()"><!--identity for all other nodes-->
   <xsl:copy>
     <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
</xsl:template>

<!--this cleans up the output when using indent="yes"-->
<xsl:template match="text()[not(normalize-space())]" mode="syntax"/>
<xsl:template match="text()[not(normalize-space())]"/>

</xsl:stylesheet>

T:\ftemp>saxon uslu.xml uslu.xsl
<?xml version="1.0" encoding="utf-8"?>
<tests>
    <assessment teds-type="T">
       <response_label>
          <material>
             <mattext texttype="text/html"><![CDATA[Select the<b>GPO Part 
Additional Info</b> link
       in the <b>Navigation</b> screen]]></mattext>
          </material>
       </response_label>
    </assessment>
    <other>
       <para>Select the<emphasis>GPO Part Additional Info</emphasis> link
     in the <emphasis>Navigation</emphasis> screen</para>
    </other>
</tests>
T:\ftemp>

--
Public courses: Spring 2004 world tour of hands-on XSL instruction
Each week:   Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO
Hong Kong May 17-21; Bremen Germany May 24-28; Helsinki June 14-18

World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc


Current Thread
Keywords