This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: XALAN does not handle document('') as expected to carry out an in-stylesheetlook-up
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] XALAN does not handle document('') as expected to carry out an in-stylesheetlook-up
- From: David_N_Bertoni at lotus dot com
- Date: Thu, 1 Nov 2001 15:12:40 -0500
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Mark,
> Hi
>
> In order to sort items by date where we are provided with the date in dd
> mmm yyyy format (e.g. 03 Jan 2001) I wanted to convert the MMM value to a
> number which can be sorted.
>
> I used the approach where I embedded a look-up within the stylesheet and
> then used the document('') function to look up the month in the table to
> get the number to sort by (see code segment below).
>
> This works fine when I run XALAN from the command line. However my
> application applies the template after reading the XSL transform from a
> database and then applying it to a document. When this occurs XALAN
> appears to be attempting to obtain a document from the file server when
my
> understanding was that the document('') function means that the lookup
> table can be held within the stylesheet itself.
>
I think you're assuming that when Xalan processes the stylesheet for use as
a stylesheet, that it also processes the stylesheet as a potential source
document. This is not the case -- In a call to the document function,
Xalan parses the stylesheet document separately, as though it were parsing
any other source document.
> Does anyone know if this is a known feature or have I missed something
> here? Your help is appreciated.
>
> Thanks
>
> Mark Clare
Working as designed. I suspect that most processors work this way, since
stylesheets are processed with the goal of building an efficient run-time
mechanism for performing the transformation described by the stylesheet.
Also, there are different rules for interpreting stylesheet xml files and
source documents. From the recommendation:
"When the first argument to the document function is not a node-set, the
first argument is converted to a string as if by a call to the string
function. This string is treated as a URI reference; the resource
identified by the URI is retrieved. The data resulting from the
retrieval action is parsed as an XML document and a tree is constructed
in accordance with the data model (see [3 Data Model])."
and
"Note that a zero-length URI reference is a reference to the document
relative to which the URI reference is being resolved; thus document("")
refers to the root node of the stylesheet; the tree representation of
the stylesheet is exactly the same as if the XML document containing the
stylesheet was the initial source document."
Of course, a processor _could_ detect references to the stylesheet by
looking for any calls to the document() function, but it would be
impossible to detect all cases, so I don't see how this would work.
You might think about using an EntityResolver to solve this problem. I'd
recommend you post a question on the Xalan mailing list for more
information.
Dave
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list