www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Question about XML/XSL links from newbie

  1. #1
    Join Date
    Apr 2009
    Posts
    8

    Question about XML/XSL links from newbie

    Hello and Greetings to all,

    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.

    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
    Last edited by xpatUSA; 04-26-2009 at 08:59 AM.

  2. #2
    Join Date
    Feb 2009
    Posts
    33
    Code:
    <xsl:value-of select="LDESC" disable-output-escaping="yes"/>
    cheers, John Bampton.

  3. #3
    Join Date
    Apr 2009
    Posts
    8

    Thumbs up

    Quote Originally Posted by JohnBampton View Post
    Code:
    <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

  4. #4
    Join Date
    Apr 2009
    Posts
    8

    Oh well . . .

    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

  5. #5
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,270
    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

  6. #6
    Join Date
    Aug 2006
    Posts
    1,904
    Have you tried CDATA tags around the description elements?

    Dave

  7. #7
    Join Date
    Apr 2009
    Posts
    8
    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

  8. #8
    Join Date
    Aug 2006
    Posts
    1,904
    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:

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

  9. #9
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,270
    I believe that you will discover that unless you disable output escaping your result will be
    Code:
    This is the most amazing &lt;a href="www.huguenin.com"&gt;Huguenin&lt;/a&gt; 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

  10. #10
    Join Date
    Apr 2009
    Posts
    8
    Quote Originally Posted by tracknut View Post
    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:

    Code:
    <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

  11. #11
    Join Date
    Apr 2009
    Posts
    8
    Quote Originally Posted by xpatUSA View Post
    Thanks Dave,

    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>
    XSL:
    Code:
    <?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

  12. #12
    Join Date
    May 2007
    Posts
    288
    I'd normally use
    <xsl:copy-of select="root/description/node()"/>

  13. #13
    Join Date
    Apr 2009
    Posts
    8
    Quote Originally Posted by jkmyoung View Post
    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

  14. #14
    Join Date
    May 2007
    Posts
    288
    Instead of
    <p><xsl:value-of select="root/description"/></p>
    have
    <p><xsl:copy-of select="root/description/node()"/></p>

  15. #15
    Join Date
    Apr 2009
    Posts
    8

    Thumbs up We may have cracked it this time . . . .

    Quote Originally Posted by jkmyoung View Post
    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>
    The result is here,

    y'all have a splendid day!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles