xsl-list
[Top] [All Lists]

[xsl] Storing XML doc refs in variables

2007-01-30 10:07:03
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

 



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>