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 May 23rd, 2007, 12:06 AM
Authorized User
 
Join Date: Apr 2005
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rendering HTML inside XML through XSL - HELP !!!

I have this xml in which I have html tags. I want to render the "<myhtml>" (as in example below) tag through my XSL while retaining its formatting. At the moment it is rendering <myhtml> tag's inner content as it is without taking care of any formatting tags :(:(

e.g.

Code:
<top>
   <myhtml>
      Some <b>bold</b> content and some <i>italic</i> content
   </myhtml>
</top>
Thanks in advance :)
 
Old May 23rd, 2007, 03:44 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's hard to tell what you're doing wrong without seeing your code, but the usual mistake that beginners make (apart from not showing people their code...) is using xsl:value-of in place of xsl:copy-of.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 23rd, 2007, 04:31 AM
Authorized User
 
Join Date: Apr 2005
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh just forgot to paste the relevant xsl:
Code:
<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes" >
.. .. ..
.. .. ..
<xsl:for-each select="/formalcomments/annotation" order-by="id">
<tr>

<td><xsl:value-of select="/top/myhtml"/></td>
</tr>
Also tried "/top/myhtml/node()" but it truncated the rest of the node's content as soonas it found first html (<b>) tag.

Using <xsl:copy-of> in place of <xsl:value-of> as per suggestion generated the following error
Code:
Keyword xsl:copy-of may not be used in namespace http://www.w3.org/TR/WD-xsl.
 
Old May 23rd, 2007, 04:46 AM
Authorized User
 
Join Date: Apr 2005
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Posting the code after a little correction (had changed the xml/xsl for simplicity :) )..

Asuming that id exists alongwith myhtml node in XML..
Code:
<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes" >
.. .. ..
.. .. ..
<xsl:for-each select="/top" order-by="id">
<tr>
<td><xsl:value-of select="id"/></td>
<td><xsl:value-of select="myhtml"/></td>
</tr>
Also tried "myhtml/node()" but it truncated the rest of the node's content as soonas it found first html (<b>) tag.

Using <xsl:copy-of> in place of <xsl:value-of> as per suggestion generated the following error
Code:
Keyword xsl:copy-of may not be used in namespace http://www.w3.org/TR/WD-xsl.
[/quote]

 
Old May 23rd, 2007, 05:14 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Oh dear, you are very confused.

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes" >

Namespace http://www.w3.org/TR/WD-xsl defines a variant of XSLT introduced by Microsoft in 1998 before the XSLT 1.0 specs were finished in 1999. It is very rarely seen nowadays, and is not documented or supported, although I believe it still runs in Internet Explorer.

Namespace http://www.w3.org/2005/02/xpath-datatypes identifies a draft of the XSLT 2.0 recommendation (not the final version).

You need to decide which version of XSLT you are trying to use.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 23rd, 2007, 10:28 AM
Authorized User
 
Join Date: Apr 2005
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got some detailed help from another forum.. here is the solution just incase..

Fixed namespaces..
Code:
<top xmlns:dataType= "urn:schemas-microsoft-com:datatypes">
and
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Selection by copy-
Code:
<xsl:for-each select="myhtml">
<xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:for-each>
..
Code:
    <xsl:template match="@*|node()" mode="copy">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates mode="copy"/>
        </xsl:copy>
    </xsl:template>


 
Old May 23rd, 2007, 10:36 AM
Authorized User
 
Join Date: Apr 2005
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
<xsl:for-each select="myhtml">
    <xsl:apply-templates mode="copy"/>
</xsl:for-each>
instead of..
Code:
<xsl:for-each select="myhtml">
<xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:for-each>





Similar Threads
Thread Thread Starter Forum Replies Last Post
html part inside xml RoeZ XSLT 3 November 28th, 2007 08:18 AM
Render HTML inside CDATA with XSL c2c XSLT 0 September 10th, 2006 11:10 AM
viewing xml inside an html file Tomi XML 1 August 2nd, 2006 05:06 AM
getting data from XML rendering with XSL louismanukonda XSLT 1 January 4th, 2006 10:37 AM
Can I define a new xsl page inside .XML file flyfish XSLT 0 August 29th, 2005 03:33 PM





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