Click to See Complete Forum and Search --> : Question about XML/XSL links from newbie


xpatUSA
04-26-2009, 09:40 AM
Hello and Greetings to all,

I collect watches. Three kinds: vintage mechanical, military and quartz. I want to migrate from my existing HTML/CSS (http://kronometric.org/tcw/) to XML/XLS, the purpose being to separate data from mark-up. The plan was to have 3 plain XML data files, each referring to a single, common XLS file. Part of the XML data (http://kronometric.org/tcw/mec/mec.xml) includes a number of description elements <LDESC>blah blah blah</LDESC>. Sometimes my blah contains HTML-style links <a href=etc etc, sometimes not. When it does, not unsurprisingly, the links appear in the browser as literal text :(.

I have read but not really understood reams of info on XSLT, XLINK, namespaces, but to no avail. All I want is the links to appear in the output as links. Googling this problem produces several hits but no understandable reasons or solutions.

Here's the two files as they stand, including an unsuccessful attempt at declaring a namespace in the first LDESC in the XML data file.

http://kronometric.org/tcw/mec/mec.xml
http://kronometric.org/tcw/mec/dev00.xsl

Please can somebody put me straight using plain English and an example or two? Pretty please??

thanks,

Ted

JohnBampton
04-26-2009, 10:36 AM
<xsl:value-of select="LDESC" disable-output-escaping="yes"/>

cheers, John Bampton.

xpatUSA
04-26-2009, 01:14 PM
<xsl:value-of select="LDESC" disable-output-escaping="yes"/>

cheers, John Bampton.
Thank you very much, John. It worked like a charm (after I turned the left brackets in that one item back into &lt; ). I was just about to give up and revert to HTML but now I'm much encouraged by both this forum and it's knowledgeable members.

Thanks again,

Ted

xpatUSA
04-28-2009, 11:57 AM
Seems I was a little quick with the jubilation :(

It worked off-line in XML Spy's browser and presumably IE but FireFox appears ignores the disable-output-escaping="yes" :(

I am already sick and tired of all these stupid browser differences. I can't bear to write code that has to account for them, either. I just collect watches!

So, sad to say, I'll just not put links in my descriptive text. Everything will then work as intended :)

thanks again,

Ted

Charles
04-28-2009, 12:08 PM
That little problem with Firefox. Oddly, MSIE gets HTML and CSS pretty much wrong but it tends to be dead on with XML and XSL. I ran into something like this before and if my memory is correct the XSLT-FO spec allows that "disable-output-escaping" doesn't have to be supported when the result is a fragment. The good folks working on Firefox decided to call all their output fragmensts and so did away with this, most useful, feature.

tracknut
04-28-2009, 12:10 PM
Have you tried CDATA tags around the description elements?

Dave

xpatUSA
04-28-2009, 12:50 PM
Hello Dave,

I'm not that advanced and currently would not know how to add CDATA tags. Can you point me in the correct direction?

thanks,

Ted

tracknut
04-28-2009, 01:04 PM
I'm about one step ahead of you on this, so my apologies in advance if this is a complete wild goose chase :)

In your XML:

<description><![CDATA[
This is the most amazing <a href="www.huguenin.com">Huguenin</a> watch.
]]></description>

Charles
04-28-2009, 01:21 PM
I believe that you will discover that unless you disable output escaping your result will be This is the most amazing &lt;a href="www.huguenin.com"&gt;Huguenin&lt;/a&gt; watch.

xpatUSA
04-28-2009, 01:23 PM
I'm about one step ahead of you on this, so my apologies in advance if this is a complete wild goose chase :)

In your XML:

<description><![CDATA[
This is the most amazing <a href="www.huguenin.com">Huguenin</a> watch.
]]></description>

Thanks Dave,

I'll give it a shot later, I'm a little burned out right now ;)

Ted

xpatUSA
04-29-2009, 12:35 PM
Thanks Dave,

I'll give it a shot later, I'm a little burned out right now ;)

Ted

Here's the result . . .

XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="dev.xsl"?>
<root>
<description><![CDATA[
This is the most amazing <a href="www.huguenin.com">Huguenin</a> watch.
]]></description>
</root>

XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Development XSL</title>
</head>
<body>
<p><xsl:value-of select="root/description"/></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Output from FireFox off-line:
This is the most amazing <a href="www.huguenin.com">Huguenin</a> watch.


So, no go yet.

later,

Ted

jkmyoung
04-29-2009, 01:56 PM
I'd normally use
<xsl:copy-of select="root/description/node()"/>

xpatUSA
04-29-2009, 07:29 PM
I'd normally use
<xsl:copy-of select="root/description/node()"/>

Sorry, I'm not knowledgeable enough to get that (still only a watch collector and aging fast ;-). How would you use it and where?

thanks,

Ted

jkmyoung
04-30-2009, 10:54 AM
Instead of
<p><xsl:value-of select="root/description"/></p>
have
<p><xsl:copy-of select="root/description/node()"/></p>

xpatUSA
04-30-2009, 12:07 PM
Instead of
<p><xsl:value-of select="root/description"/></p>
have
<p><xsl:copy-of select="root/description/node()"/></p>

Ah, now I see . . the copy should be faithfully copied to the output as-is without interference from the browser's parser. Indeed, it worked locally on xmlSpy's browser but FireFox still would not have it, neither off- nor on-line.

After going down many trails involving namespaces and even Xlink, I've ended up with this (a sort of browser written in xsl :rolleyes:). So now links come out OK in IE and FF off- and on-line:D.


<xsl:for-each select="WATCH/ITEM/LDESC/node()">
<xsl:choose>
<xsl:when test="name()='a'"><!-- when the name of the current node is 'a' then create a link with the values of the current element's attribute and text -->
<a><xsl:attribute name="href">
<xsl:value-of select="attribute::href"/>
</xsl:attribute>
<xsl:value-of select="."/>
</a>
</xsl:when>
<xsl:otherwise>
<!-- else output the current node's text -->
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>


The result is here (http://kronometric.org/xml/dev.xml),

y'all have a splendid day!

Charles
04-30-2009, 12:13 PM
Yes, that's how you have to do it for Firefox. See my post above for the reason.