RE: [xsl] document() function and error-handling

Subject: RE: [xsl] document() function and error-handling
From: "Scott Trenda" <Scott.Trenda@xxxxxxxx>
Date: Thu, 3 Jan 2008 12:56:53 -0600
Martin/Dmitre -

If I were working in ASP.NET or something similar where I could
manipulate the actual DOMDocument objects at will before the
transformation, those would be fine suggestions; however, I'm actually
doing this via a ColdFusion-like preprocessor, where I only can define
the XML source (text or file), the XSLT stylesheet (text/file), the
stylesheet parameters, and the output variable/file. The preprocessor
sets up and makes the actual call to MSXML itself, out of my control.
Anthony Nassar's suggestion about the XmlResolver class might prove
invaluable, as my company owns the preprocessor and we can have it
altered to support a better URL-resolving method, but even after that,
I'll still be limited to the functionality available from within the
stylesheet itself. (I've had trouble using msxsl:script in the past; the
preprocessor might not support that, either. No idea why.)

My current workaround for the URL issue is to run a preparatory
transformation on the document and replace URL references with a block
of script code that validates whether or not the file exists, replacing
the URL with a blank string if not. I'll evaluate that when the
transformation returns and transform the evaluated result with a
stylesheet that resolves the URLs, knowing they've already been checked
to prevent errors. (Quick example of the source document from the
process included below.) My original question was basically asking if
there were a way that I could avoid this preliminary transformation,
without altering the properties of the actual XSLT processor object used
to make the transformation.

Thanks for the replies!

~ Scott

original source document:
  <menu url="/some/other/path/to/a/similar/menu/file.xml"/>
    <menu link="/some/page.html" title="you get the point"/>
    <menu url="/repeat/url/references/ad/nauseum.xml"/>

result of the preliminary transformation:
ToPhysicalPath("/some/other/path/to/a/similar/menu/file.xml"), "")#"/>
    <menu link="/some/page.html" title="you get the point"/>
ToPhysicalPath("/repeat/url/references/ad/nauseum.xml"), "")#"/>

preprocessor-evaluated result, to be used as the next source document
(for this example, the first file doesn't exist, but the second does):
  <menu validURL=""/>
    <menu link="/some/page.html" title="you get the point"/>
    <menu validURL="D:\repeat\url\references\ad\nauseum.xml"/>

Then the same stylesheet can convert @url to @validURL with the
FileExists() wrapper and use document() on @validURL, and the
preprocessor script can just loop until the evaluated result of the
transformation is the same as the unevaluated one.

I suppose that's a little more than most would care to read, but it's
the first workaround I see. Comments?

-----Original Message-----
From: Martin Honnen [mailto:Martin.Honnen@xxxxxx]
Sent: Thursday, January 03, 2008 11:55 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] document() function and error-handling

Joe Fawcett wrote:

> Well you could always write your own doc-available() function using an

> msxsl:script element and the FileSystemObject.

Or simply, as there are already parameters
               <xsl:param name="framework-map-file"/>
             <xsl:param name="app-map-file"      />
which you set before you run the transformation, instead of passing in a

URL you can pass in an MSXML DOMDocument itself only if the document
loads fine e.g. assuming you use VBScript and MSXML 3 you do

  <xsl:param name="framework-maps" select="/.."/>

   Set xmlDoc = Server.CreateObject("Msxml2.DOMDocument.3.0")
   xmlDoc.async = False
   If xmlDoc.load(Server.MapPath("file.xml")) Then
     xslProcessor.addParameter "framework-maps", xmlDoc
     ' handle xmlDoc.parseError here
   End If


	Martin Honnen

-----Original Message-----
From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx]
Sent: Thursday, January 03, 2008 11:38 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] document() function and error-handling

Open the document prior to starting the XSLT transformation, then pass
it as parameter to the transformation (in case the file did not exist,
pass an empty node-set as the value of the parameter).

Read more about the  IXSLProcessor.addParameter()  method.

Dimitre Novatchev
Truly great madness cannot be achieved without significant intelligence.
To invent, you need a good imagination and a pile of junk
Never fight an inanimate object
You've achieved success in your field when you don't know whether what
you're doing is work or play

Current Thread