Re: problem self-referencing using document('') to reference parameters

[email protected] 26 Apr 2007 06:27:16 -0700
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Organization http://groups.google.com
Message-ID <[email protected]>
On Apr 25, 6:21 pm, Jonas Sicking <[email protected]> wrote:
> [email protected] wrote:
> >> I think this is a bug, I have filed
> >> <https://bugzilla.mozilla.org/show_bug.cgi?id=378610> about that.
>
> > Thanks Martin. Please let me know if there is a workaround.
>
> There's good and bad news.
>
> The bad news is that even though there is a bug there, it's not the bug
> you think it is. What we IMHO ideally should return for document('') in
> that case is the page that is executing the javascript. The long
> description is in the bug, the short story is simply that the URI ''
> should be resolved against where it appears, and it appears in your page.
>
> The good news is that there is most likely another way of doing what
> you're trying to do. Exactly why do you want to refer to the xslt
> document itself? One way of doing so would be to use .setParameter to
> pass the DOM of the stylesheet as a parameter and then refer to the
> stylesheet through that parameter.
>
> Best Regards,
> Jonas Sicking

Jonas,

Interesting that you said the "URI should be resolved against...your
page". This is how MSXML6 and MSXML4 have implemented the behavior. As
stated in the W3C and quoted in the bug report you sited earlier, the
document('') should refer to the XSLT. However, I can see how the
assumption that the XSLT is referenced by a URI and not a string would
make the W3C statement more of a conclusion than an imperative. It's
easy to visualize the programmer trying to resolve the URI ('') when
the XSLT has no URL and therefore uses the URL of the web page
containing the XSLT string.

But back to the problem at hand. How does an XSLT refer to itself? In
ASP.NET, the XSL processor accepts a resolver object which can have a
copy of the XSLT string. Here's the scenario. It's a technique I
originally picked up in Doug Tidwell's (not me) book "XSLT" by
O'Reilly. The XSLT contains one or more XML snippets essentially used
as look-up tables within the transform. In the sample XSLT I provided
earlier (Apr 24, 9:34 am), note the <dl:root>...</dl:root> element. In
the real XSLT, the document('') function is used to access the
<dl:root> element. Please keep in mind that the XSLT itself is created
at run-time; it's not static. Therefore, it's not reasonable to have
the <dl:root> element in a separate file; it's created at run-time
too. In fact, it's created by another XSLT and since XSLT 1.0 can only
output one file, it's particularly inconvenient to create more than
one file.

Thanks for mentioning the setParameter workaround. In my case, it's a
little more complicated because the code that generates the XSLTs
would need to be changed to use an <xsl:param> instead of the
document('') function. Given the large number of XSLTs used in my
application it's not a trivial change, but I'll consider it.

Thanks,
Doug D