[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Storing XML doc refs in variables

Subject: Storing XML doc refs in variables
From: "Rick Livesey" <rick.livesey@xxxxxxxxxxxx>
Date: Tue, 30 Jan 2007 12:06:00 -0500
 Storing XML doc refs in variables
Hi all,

I'm a bit new to XSL so please excuse me if I'm asking a daft question:

I need to be able to load multiple XML documents (using the document()
function) and store the resultant document node within a variable,
(since I don't want to load the document every time I need to access the
data inside).
This is easy enough using the following statement:

<xsl:variable name="styleXMLDoc" select="document('styles.xml')" />

However, on some occasions styles.xml may not exist, and causes an
exception in the XSL engine, so to get around this I attempted to use
the XSL2 doc-available() function:

 <xsl:variable name="styleXMLDoc" >
  <xsl:choose >
    <xsl:when test="doc-available('styles.xml')">
      <xsl:value-of select="document('styles.xml')"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:document />
    </xsl:otherwise>
  </xsl:choose>
 </xsl:variable>

The theory was that if styles.xml didn't exist, an empty document node
would be created and assigned to the variable, meaning any future use
would simple return an empty results set.

However this code doesn't work (the variable is assigned, but I think
it's being assigned as type text) and I can't figure out whether it's
because you can't have a non-determinant variable that contains document
nodes (unlikely) or whether the dummy document node created in the
'otherwise' branch is not syntactically correct, therefore the engine
doesn't know what type to assign the variable.

Any help / examples would be greatly received,

Rick

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.