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 December 7th, 2009, 03:56 PM
Authorized User
 
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
Default Open an XML document with an XSL?

So I currently have an XSL which is parsed against a file called test.xml. Within the XSL I have a variable which selects a value from a different xml called creation_YYYY.xml (yyyy = year). Since the YYYY value of the creation file changes every year I can't hardcode a value within the XSL, so I use the year value found in the test.xml (which may or may not match the value of the creation xml). So the issue that i am having is that if the YYYY doesn't match the year value in the test.xml then the XSL crashes. So...

I have the following two XML's.
- test.xml
- creation_2010.xml (YYYY= 2010)

The year value in test.xml is 2009, so clearly the YYYY of the creation xml does not match, and the xsl currently doesn't run. What I want to do is something like: if year value in test.xml does not match creation_YYYY.xml then don't open the document(like an exception handler) and continue processing the rest of the code in the xsl.

Here is a snippet of the strucutre of test.xml
Code:
<xml file>
  <date month="12" date="07"/>
  <season year="2009"/>
   etc...
</xml file>
In my XSL(which i parse against test.xml) I have the following code:
Code:
<xsl:variable name="YYYY" select="//season/@season"/>
<xsl:variable name="xmlTest" select="document(concat('Creation_', $YYYY, '.XML'))"/>
So I just wanted to know if there is some way of doing an exception on the xmlTest varaible if it does not exist.

Last edited by vb89; December 7th, 2009 at 04:18 PM..
 
Old December 7th, 2009, 04:19 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 1.0 it's left up to the processor to decide what happens if you call document() with a URI that can't be found. Some processors give you options on this, others take the default action which is a fatal error. There's no way of catching this error.

XSLT 2.0 has a function doc-available() which allows you to test whether a document exists before opening it.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
vb89 (December 7th, 2009)
 
Old December 7th, 2009, 04:29 PM
Authorized User
 
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Yeah, unfortunately i'm using XSLT 1.0 so the processor currently crashes. Is there possibly a way of putting the document() inside an xsl:if or something of that nature?
 
Old December 7th, 2009, 04:41 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If your processor allows you to write extension functions (e.g in Java or Javascript) then you could solve the problem that way, by writing a function that tests for the existence of the file.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
IE open document reference bobbyastrain Pro VB 6 1 December 30th, 2007 08:47 AM
Using XML Spy and an XSL document. AjayLuthria XSLT 3 June 12th, 2007 02:43 PM
Open document, Open second doc and copy to first justabeginner Word VBA 1 March 7th, 2007 02:47 AM
document.open() issue fs22 Javascript 8 September 16th, 2004 09:07 PM
faild to open document polash Crystal Reports 0 March 22nd, 2004 06:18 PM





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