[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] How to gracefully check if a document exists relative to the document being transformed?


Subject: RE: [xsl] How to gracefully check if a document exists relative to the document being transformed?
From: "Houghton,Andrew" <houghtoa@xxxxxxxx>
Date: Thu, 4 Feb 2010 20:28:30 -0500

If you are using XSLT 2.0, then doc-available().  Only works for XML
documents, but that's what you are doing below.

Andy.

> -----Original Message-----
> From: Calvados Boulard [mailto:calvados.boulard@xxxxxxxxx]
> Sent: Thursday, February 04, 2010 06:55 PM
> To: xsl-list
> Subject: [xsl] How to gracefully check if a document exists relative to
> the document being transformed?
>
> Hi there,
>
> I'm transforming a XML document, and attempting to determine if a file
> at a relative location exists.
>
> The file as you would guess from the relative path exists one
> directory up, and in another directory
>
> Currently I'm using:
>
> <xsl:choose>
>             <xsl:when test="unparsed-text-available('../06_Regulations
> Point in Time/125_2008_pit.xml')">
>                 <h1>Document found</h1>
>             </xsl:when>
>             <xsl:otherwise>
>                 <h1>Document NOT found</h1>
>             </xsl:otherwise>
> </xsl:choose>
>
> However the unparsed-text-available only seems to check for the target
> document relative to the location of the XSL file, not the XML.
>
> I've also tried:
> <xsl:choose>
>         <xsl:variable name="common-uri"
> select="resolve-uri('../06_Regulations Point in
> Time/125_2008_pit.xml')" />
>         <xsl:choose>
>             <xsl:when test="unparsed-text-available($common-uri)">
>            <h1>Document found</h1>
>             </xsl:when>
>             <xsl:otherwise>
>                 <h1>Document NOT found</h1>
>             </xsl:otherwise>
> </xsl:choose>
>
> as well as:
> <xsl:choose>
>              <xsl:when
> test="unparsed-text-available(document(''../06_Regulations Point in
> Time/125_2008_pit.xml',/))">
>              <h1>Document found</h1>
>             </xsl:when>
>             <xsl:otherwise>
>                 <h1>Document NOT found</h1>
>             </xsl:otherwise>
> </xsl:choose>
>
>
> How would I go about gracefully checking to see if the document exists
> relative to the document being transformed?  I see that the document
> function has a way to enforce checking relative locations, but am
> unsure how to put this all together.
>
> Thanks for all your help.
>
> Cal.


Current Thread
Keywords