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

RE: parse inside a cdtata

Subject: RE: parse inside a cdtata
From: Jarno.Elovirta@xxxxxxxxx
Date: Tue, 3 Jun 2003 15:24:29 +0300
cdtata
Hi,

> I d like to know if it's possible to parse a cdata content in XSL.
> I have something like this:
> <CONTENT TYPE="text/html"><![CDATA[<p align="left"><font 
> size="12"></font><font size="12" face="tahoma" 
> color="#000000">one</font></p><p align="left"><font 
> size="12"></font></p>]]></CONTENT>

There are extension functions to do this in some XSLT engines, but other than that, you have to either preprocess the document or write an XML parser in XSLT.

> Or may be is there a way to get the unformatted html text of a cdata? 
> ("one" in my example)

Preprocess the data, since XSLT works on trees, not character data that is an SGML document fragment. You can, of course, write an template like

  <xsl:template match="CONTENT" name="character-parser">
    <xsl:param name="text" select="."/>
    <xsl:choose>
      <xsl:when test="contains($text, '&lt;')">
        <xsl:value-of select="substring-before($text, '&lt;')"/>
        <xsl:call-template name="character-parser">
          <xsl:with-param name="text" select="substring-after(substring-after($text, '&lt;'), '>')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

that will give "one" with the input above, I'm pretty sure it won't take long for you to get input that will not be handled by your parser stylesheet. Fix your input.

Cheers,

Jarno - Neurotic Fish: Wake Me Up

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.