Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 2nd, 2005, 10:32 AM
Registered User
 
Join Date: Oct 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default xhtml-tags i xml value-of select

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 &lt and &gt 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

 
Old October 2nd, 2005, 10:42 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you show your source document? It looks like your XHTML maybe just text.

Or perhaps you want copy-of instead of value-of:
Code:
<xsl:copy-of select="TEXT" />
--

Joe
 
Old October 2nd, 2005, 03:05 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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>&lt;b>text&lt;/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
 
Old October 3rd, 2005, 11:52 AM
Registered User
 
Join Date: Oct 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>

 
Old October 3rd, 2005, 11:59 AM
Registered User
 
Join Date: Oct 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>

 
Old October 3rd, 2005, 12:15 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
html tags to reformed to xhtml standard using xsl swapbpl XSLT 12 May 8th, 2008 05:38 AM
regarding deleting tags in an xml abhi.prince4u XML 0 July 14th, 2007 12:16 AM
XML tags getting converted during exchange Koushik XML 7 December 7th, 2006 06:25 PM
Generating XML tags on the fly francislang XSLT 3 September 6th, 2004 05:21 AM
Renaming with XML tags? johrik XSLT 1 February 12th, 2004 03:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.