[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: CDATA question

Subject: Re: CDATA question
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 14 Apr 2004 17:35:47 -0400
xsl cdata
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.