View Full Version : HTML tags in XML
marcus1060
03-27-2008, 01:13 AM
I'm new to XML, and I've been trying to find out how to parse an HTML tag that is in XML.
For example:
<something>
<text>
<strong>Hey</strong>
Or <a href="#">nothing</a>
</text>
</something>
I know it's something I've got to do in the XSLT, but I've had no luck what so ever.
Thanks.
bonekrusher
03-27-2008, 02:35 AM
Hi,
Are you trying to convert your XML to HTML? You can use XSLT. What is your desired output?
HTH
Bones
marcus1060
03-27-2008, 05:42 PM
Right now I just have it set up so that the XSL just layouts the XML.
But HTML tags are just displayed like normal.
I'm just wondering how to make XSL actually make them have their effect, or so to speak.
Len Whistler
03-28-2008, 04:44 AM
I'm also learning XML and what I gather is if you are only outputting the XML data as it has been entered and do not need to manipulate it then it's best, and easiest to use a style.css file.
BUT
If you will be out putting the XML data and need to manipulate it - adding sales tax, adding columns, order by a specific column, etc. - then you have to use a style.xsl file
oesxyl
03-28-2008, 06:10 AM
Right now I just have it set up so that the XSL just layouts the XML.
But HTML tags are just displayed like normal.
I'm just wondering how to make XSL actually make them have their effect, or so to speak.
try this:
test.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xml" href="test.xsl"?>
<something>
<text>
<strong>Hey</strong>
<a href="#">nothing</a>
</text>
</something>
test.xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
encoding="utf-8"
indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>XML + XSLT Test</title>
</head>
<body>
<xsl:apply-templates select="something"/>
</body>
</html>
</xsl:template>
<xsl:template match="something">
<h1>
<xsl:value-of select="text/strong"/>
</h1>
<h2>
<xsl:value-of select="text/a/@href"/>
</h2>
<h3>
<xsl:value-of select="text/a"/>
</h3>
</xsl:template>
</xsl:stylesheet>
both files in the same directory, use firefox, load test.xml
best regards
marcus1060
03-29-2008, 03:37 AM
That's not really what I mean.
I already have an XML page and XSL stylesheet.
(located at http://noveis.net)
And I just want to know if it's possible to make the XSL sheet match HTML tags regardless of where they are, and parse them.
oesxyl
03-29-2008, 03:54 AM
That's not really what I mean.
I already have an XML page and XSL stylesheet.
(located at http://noveis.net)
And I just want to know if it's possible to make the XSL sheet match HTML tags regardless of where they are, and parse them.
as bonekrusher said "What is your desired output?"
I add, what is your inputs? because is not clear for me what do you want to say about HTML tags and parse.
Give an example, please.
best regards.
marcus1060
03-29-2008, 10:36 AM
What I mean is I'm going to have the XML like this:
<onething>
<something>
<title>Hey!!</title>
<text>
<strong>Hey</strong>
Or <a href="#">nothing</a>
</text>
</something>
<something>
<title>What?</title>
<text>
This is something completely else. <a href="here.html">See here</a>
</text>
</something>
</onething>
Then in XSL:
[...]
<xsl:for-each select="onething/something">
<h2><xsl:value-of select="title"/></h2>
<p>
<xsl:value-of select="text"/>
</p>
</xsl:for-each>
[...]
Then that would output:
<h2>Hey!!</h2>
<p><strong>Hey</strong>
Or <a href="#">nothing</a></p>
<h2>What?</h2>
<p>
This is something completely else. <a href="here.html">See here</a>
</p>
I just want the HTML in the text element to actually come into use, not just outputted as the tags. Like what happens now.
I don't know what the HTML is going to be in the text element, so I can't just use what said above.
oesxyl
03-29-2008, 11:16 AM
You want to embed fragment of html inside of the text element?
If this is what you want you could do this way:
test.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xml" href="test.xsl"?>
<onething>
<something>
<title>Hey!!</title>
<text><![CDATA[
<strong>Hey</strong>
Or <a href="#">nothing</a>
]]></text>
</something>
<something>
<title>What?</title>
<text><![CDATA[
This is something completely else. <a href="here.html">See here</a>
]]></text>
</something>
</onething>
test.xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
encoding="utf-8"
indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>XML + XSLT Test</title>
</head>
<body>
<xsl:apply-templates select="onething/something"/>
</body>
</html>
</xsl:template>
<xsl:template match="something">
<h2>
<xsl:value-of disable-output-escaping="yes"
select="text"/>
</h2>
</xsl:template>
</xsl:stylesheet>
output:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>XML + XSLT Test</title>
</head>
<body>
<h2>
<strong>Hey</strong>
Or <a href="#">nothing</a>
</h2>
<h2>
This is something completely else. <a href="here.html">See here</a>
</h2>
</body>
</html>
regards
marcus1060
03-29-2008, 11:34 AM
You'd think I would have figured that out through Google...
Sigh...
Hmm... works in IE8, but no FF. Interesting.
oesxyl
03-29-2008, 11:46 AM
You'd think I would have figured that out through Google...
Sigh...
Hmm... works in IE8, but no FF. Interesting.
try to clean the cache. If after that you don't see the same thing then the firefox is the corect version, :)
I don't have nothing against ie, I don't have ie at all because I on linux, :)
I tested with ffox and with the output I posted, it works.
Probably to achive what you want you must adjust both the xml and xslt files.
best regards
marcus1060
03-29-2008, 11:54 AM
Yeah I tried clearing the cache and what not.
Working in Firefox 2, but not 3 beta, odd.
oesxyl
03-29-2008, 12:11 PM
Yeah I tried clearing the cache and what not.
Working in Firefox 2, but not 3 beta, odd.
mine is iceweasel 2.0.0.12, is in fact ffox 2.
regards
marcus1060
03-30-2008, 03:56 AM
Looks like this is on purpose by Firefox.
Guess I have to find another way around it.
http://www.codingforums.com/showthread.php?p=671154
Recommendations anyone?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.