I collect watches. Three kinds: vintage mechanical, military and quartz. I want to migrate from my existing HTML/CSS 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 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.
Thank you very much, John. It worked like a charm (after I turned the left brackets in that one item back into < ). 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.
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
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.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
I believe that you will discover that unless you disable output escaping your result will be
Code:
This is the most amazing <a href="www.huguenin.com">Huguenin</a> watch.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
I'll give it a shot later, I'm a little burned out right now
Ted
Here's the result . . .
XML:
Code:
<?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>
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 ). So now links come out OK in IE and FF off- and on-line.
Code:
<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>
Bookmarks