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 24th, 2008, 12:28 PM
Authorized User
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default HTML code from XML to display using XSL

Code:
<folder name="meta_information">
            <entry name="name">kings</entry>
            <entry name="description">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name="qrichtext" content="1" /&gt;&lt;style type="text/css"&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"&gt;
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"&gt;i want to know something abt this &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</entry>
        </folder>
description has the html code - which has the data (" I want to know something abt this").
when I get the <xsl:value-of> writes complete Html code.

Is there any way to do display only the data?



 
Old October 24th, 2008, 12:46 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Unfortunately, by escaping all the markup, you've made the data very inaccessible. It's a shame to use XML this way - the whole point of the markup is to create useful structure which adds value to your information, and escaping it to hide the structure seems a really bad idea because it removes all this added value.

What you need to do here is to double-parse the content of the <entry> element. The first parse gives you the content of the <entry> element as text; you then need to feed this back into an XML (or HTML) parser to turn it into a tree, which you can navigate using XPath. At first sight it looks as if the content is well-formed XML, which means you can parse it in Saxon using the saxon:parse() extension function, or in another processor you could write your own extension function to take a string as input and return the parsed document tree.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 24th, 2008, 12:58 PM
Authorized User
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks michael...

Its old xml document(different extension) which I renamed to xml .. which gets written from a software.

I will try to work on it .. this weekend .. and let u know ..

Have a great weekend.

cheers


 
Old October 27th, 2008, 04:38 AM
Authorized User
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, when I retrieve the Entry tag value, It gives a complete HTML file.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" />
<style type="text/css"> p, li { white-space: pre-wrap; }
</style>
</head>

<body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">

<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">i want to know something abt this 
</p>

<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">lets see how this works .. 
</p>

<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">hopefully before monday
</p>
</body>
</html>
Now I have this complete text(HTML code) in a variable.

But I don't know how to use XPATH on this variable or HTML parser on this variable. I tried using for each on $variable but failed.
 
Old October 27th, 2008, 04:44 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You haven't made clear whether the content of the <Entry> element contains this HTML as a tree of nodes, or as a string containing lexical HTML markup. If it contains lexical HTML markup then you will need to parse it before you can address into it using XPath.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 27th, 2008, 04:46 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Oh, sorry, I didn't realize your latest post was a follow-on to an existing thread. I think I answered the question in my previous response: because you have carefully escaped all the markup, you will need to parse the HTML a second time.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 27th, 2008, 08:11 AM
Authorized User
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you michael for your reply and suggestion.

I made a workaround to get the string out of the htmlcode(string)
using substring(after & before). It works for my purpose as I need to get it from a <p> tag only.

Thanks.










Similar Threads
Thread Thread Starter Forum Replies Last Post
Rendering HTML inside XML through XSL - HELP !!! jilly XSLT 6 May 23rd, 2007 10:36 AM
xml to html with xsl boblavinsky XSLT 4 January 5th, 2007 05:30 AM
display directories and files using only xsl/xml.. eteune XSLT 1 January 2nd, 2007 07:01 PM
display Xml ( which refer XSL ) By Servlet pandian XSLT 0 December 24th, 2005 06:33 AM
XML/XSL to actual HTML tcstom XML 3 December 9th, 2005 01:36 PM





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