|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: parse inside a 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, '<')">
<xsl:value-of select="substring-before($text, '<')"/>
<xsl:call-template name="character-parser">
<xsl:with-param name="text" select="substring-after(substring-after($text, '<'), '>')"/>
</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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








