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 April 26th, 2007, 10:39 PM
Authorized User
 
Join Date: Apr 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default Firefox - XSLT - document.links has no properties

My XSLT generates xhtml which contains javascript instructions for manipulating document.links (all the links in the page). IE7's javascript works fine, but Firefox fails to find document.links within XSLT-generated xhtml; instead, I get this error:
Quote:
quote:document.links has no properties
Has anyone else seen this problem? Is there another way to reference all a document's entire set of links in Firefox when we're using XSLT?

Thanks!



 
Old April 27th, 2007, 02:13 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Does this problem occur if you use the document.links in a static HTML file rather than an XSLT generated one? It should be easy to test, just use view-source to get the output of the transform if you don't have it saved already. If you do get the error then it's an HTML/script problem, nothing to do with XSLT. If you don't then show small reproducible versions of the XML and XSLT and how you are doing the transform.

--

Joe (Microsoft MVP - XML)
 
Old April 27th, 2007, 08:54 AM
Authorized User
 
Join Date: Apr 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's a simple example:

test-document-links.xml:
Code:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test-document-links.xsl"?>
<test />
test-document-links.xsl:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html" indent="yes" encoding="iso-8859-1"
  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  omit-xml-declaration="yes" />
<xsl:preserve-space elements="*" />

<xsl:template match="/test">
  <html>
    <head>
      <title>Test Document Links</title>
      <script type="text/javascript">
function handleLoad() { alert("Links on page: " +  document.links.length); }
      </script>
    </head>
    <body onload="handleLoad()">
      <p><a href="#">this is a link</a></p>
    </body>
  </html>
</xsl:template>
</xsl:stylesheet>
Firefox says document.links.length = "0" for xml+xslt, "1" for static xhtml. Opera and IE7 say "1" for both xml+xslt and static xhtml.
 
Old April 27th, 2007, 10:34 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

It works fine for me on IE and Firefox as a static file:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Document Links</title>
<script type="text/javascript">
function handleLoad() { alert("Links on page: " +  document.links.length); }
</script>
</head>
<body onload="handleLoad()">
<p><a href="#">this is a link</a></p>
</body>
</html>
I agree it fails in Firefox when dynamic but not in IE. I tried changing xsl:output/@method to "xml" as it should be but that didn't help. It does work if you change the function to:
Code:
function handleLoad() { var colLinks = document.getElementsByTagName("a"); alert("Links on page: " +  colLinks.length); }

--

Joe (Microsoft MVP - XML)
 
Old April 27th, 2007, 12:21 PM
Authorized User
 
Join Date: Apr 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks! getElementsByTagName("a") will grab anchors too, though, right?
Code:
<a href="#foo">this is a link</a>
<a name="foo">this is not a link</a>
 
Old April 27th, 2007, 12:35 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Yes, if that's a problem loop through the collection and add those that have an href attribute to their own array.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting Custom Document Properties for Word Doc jayanth_nadig XSLT 2 October 30th, 2007 03:31 AM
Client side XSLT not working in FireFox ole_v2 XSLT 1 November 13th, 2006 06:26 PM
Object Properties & document.activeElement interrupt Javascript How-To 4 April 21st, 2005 03:49 PM
XSLT for links bmains XSLT 5 February 10th, 2005 08:38 AM
How to Create Links to Word Document frm Reports sundarakshi Crystal Reports 0 November 6th, 2004 02:19 AM





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