|
Subject:
|
xhtml-tags i xml value-of select
|
|
Posted By:
|
patric_jansson
|
Post Date:
|
10/2/2005 10:32:46 AM
|
Hi
I have a problem i cant get to work. In my tranforms I cant get the output to treat my strings containing xhtml-tags as html. Instead they get renderd as text (ie: <B>This text should be bold.</B> ). I have tried replacing < and > with the xml entity values. But with no luck.
This is part of my xslt fil.
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" omit-xml-declaration="yes" standalone="yes" indent="yes" media-type="application/xhtml" />
<xsl:template match="ITEM_TEXT"> <div xmlns="http://www.w3.org/1999/xhtml"> <xsl:attribute name="class">normal</xsl:attribute> <xsl:value-of select="TEXT" /> </div> </xsl:template>
Anybody who can help me, I have been stuck for days now.
Thanks in advance. Patric
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
10/2/2005 10:42:14 AM
|
Can you show your source document? It looks like your XHTML maybe just text.
Or perhaps you want copy-of instead of value-of:
<xsl:copy-of select="TEXT" />
--
Joe
|
|
Reply By:
|
mhkay
|
Reply Date:
|
10/2/2005 3:05:14 PM
|
Need to see what your XML looks like.
I suspect the problem is that your source XML doesn't contain html tags at all.
Perhaps it contains something like this:
<para><![CDATA[<b>text</b>]]></para>
or this:
<para><b>text</b></para>
Both of these notations are saying "this stuff might look like markup, but it isn't, and I don't want it treated as such". And surprise, the XSLT then treats it as ordinary text, not as markup.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
patric_jansson
|
Reply Date:
|
10/3/2005 11:52:14 AM
|
Hi Michael and Joe
Thank you for answering.
Yes my content is CDATA. What should it be? Seams like I have tried everything (although my xsl knowledge is ...)
<ITEM_TEXT id="73" type="Wsa.Core.Models.Item"> <ITEM_ID>73</ITEM_ID> <LAYOUT_ID>7</LAYOUT_ID> <HEADER><![CDATA[NULL]]></HEADER> <TEXT><![CDATA[<B>This should be bold</B>]]></TEXT> </ITEM_TEXT>
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" omit-xml-declaration="yes" standalone="yes" indent="yes" media-type="application/xhtml" />
<xsl:template match="ITEM_TEXT"> <div xmlns="http://www.w3.org/1999/xhtml"> <xsl:attribute name="class">normal</xsl:attribute> <xsl:value-of select="TEXT" /> </div> </xsl:template>
|
|
Reply By:
|
patric_jansson
|
Reply Date:
|
10/3/2005 11:59:07 AM
|
Hi Micheal and Joe
Thank you for helping me out!
Yes the <TEXT> element is CDATA, so thats wrong. Which a good thing, because then we are on the way to solve my problem(?). But what should I do? It seams like I have tried everything, although maybe I have to catch up on my XSL.
<ITEM_TEXT id="73" type="Wsa.Core.Models.Item"> <ITEM_ID>73</ITEM_ID> <HEADER><![CDATA[NULL]]></HEADER> <TEXT><![CDATA[<B>This should be bold</B>]]></TEXT> </ITEM_TEXT>
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" omit-xml-declaration="yes" standalone="yes" indent="yes" media-type="application/xhtml" />
<xsl:template match="ITEM_TEXT"> <div xmlns="http://www.w3.org/1999/xhtml"> <xsl:attribute name="class">normal</xsl:attribute> <xsl:value-of select="TEXT" /> </div> </xsl:template>
|
|
Reply By:
|
mhkay
|
Reply Date:
|
10/3/2005 12:15:59 PM
|
It would be much easier if you didn't use CDATA. You want to treat the <B> and </B> tokens as tags, so why have you added the CDATA notation which tells the parser not to treat them as tags?
If you're presented with badly designed XML like this, you can sometimes solve the problem by copying the text to the output using disable-output-escaping="yes". This only works in some environments, for example it fails under Mozilla (the reason being that Mozilla doesn't serialize the result tree, and d-o-e only has any effect when serializing).
The CDATA has caused the enclosed text not to be parsed, and the real solution lies in extracting the unparsed text and giving it to a parser to turn into a tree. In Saxon you can do that using saxon:parse().
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|