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 July 19th, 2006, 04:37 AM
Authorized User
 
Join Date: May 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Use of key and document

When I use these different kinds of calls I get the same (good)results. Does anyone know if there is a difference and why and when to use them:
   <xsl:value-of select="document('reference.xml' )/key('ref' , current()/value )" />
      <xsl:value-of select="doc('reference.xml' )/key('ref' , current()/value )" />
      <xsl:value-of select="key('ref' , current()/value,document('reference.xml' ))" />
      <xsl:value-of select="key('ref' , current()/value,doc('reference.xml' ))" />
 
Old July 19th, 2006, 10:00 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I should mention for other readers that these are all XSLT 2.0 constructs.

The differences between doc() and document() are mainly (a) that document() can take a sequence of URIs and return a sequence of documents, whereas doc() only handles one, and (b) that document(), if given a node rather than a string as its argument, resolves relative URIs relative to the base URI of that node, rather than the base URI of the stylesheet.

The differences between $node/key(A, B) and key(A, B, $node) are mainly that (a) the context node for evaluation of b is different for the two cases, and (b) the second form searches the subtree rooted at $node, not the whole document.

In your cases these distinctions make no difference to the result.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 21st, 2006, 11:27 AM
Authorized User
 
Join Date: May 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx for this information this is a great help. for understanding the differences

I still have some differences when I use absolute paths with http: protocol.
Before I want to get a value from an external xml document with this key construction, I want to test if it is a really available document.
But I never seem to get a true value when I use the new (version 2.0) doc-available function for absolute paths with the http: protocol (When I am testing a local file with the file protocoI )

<xsl:if test="doc-available('http://www.mydomain.nl/xsd/mylist.xml')" > is always false
but the relative paths like
<xsl:value-of select="doc-available('../xsd/mylist.xml')" /> is true.
And the absolute path (on my mac)
<xsl:value-of select="doc-available('file:/Volumes/www/xsd/mylist.xml')" /> is true.
and also when I use the resolve-uri() function for creating absolute paths for local files

how come? does doc-available not recognice http:paths when testing locally?
 
Old July 21st, 2006, 11:51 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

(a) Which XSLT 2.0 processor are you using?

(b) Is your site behind a firewall?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 25th, 2006, 03:48 PM
Authorized User
 
Join Date: May 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The difference is in the environment.
When I do the same test on a windows computer with the same processor saxon8 on windows doc-available() finds the http: referenced documents and on my mac I get the doc-available false boolean as result. I've shutdown the firewall on my mac for it. anyone else have that problem?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
Using key() and <xsl:key> freddy XSLT 2 January 18th, 2007 08:55 PM
<bean:message key="PNR.INPUT"/> key has null value warsha_14 Struts 1 November 13th, 2006 07:26 AM
TAB KEY working together KEY PRESS event thomaz C# 4 August 20th, 2006 02:47 PM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM





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