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

RE: [xsl] XSLT and XInclude?


Subject: RE: [xsl] XSLT and XInclude?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 23 Mar 2009 11:18:48 -0000

> I've come across some documents that are using XInclude to 
> fragment a larger tech manual. I've got the basic stylesheet 
> working that reads the document name from the href and then 
> opens it with the doc() function.

Are you sure you need to handle this in the XSLT stylesheet? Many XML
parsers have built-in support for XInclude if you set the right options.
Short of this, there are free-standing XInclude processors, including some
written in XSLT. I think it would be better to do XInclude processing as a
separate step from transformation.
> 
> In this particular case, I'm able to process the content 
> properly as the included document has a regular structure 
> that I can process directly. I got to thinking though that I 
> might need to process these included files within the context 
> of their use/placement in the referencing document.
> 
> I would like to somehow pass the context in the parent 
> document to the doc function and possibly the current 
> template mode. 

What would the doc() function do with this information? Surely you want to
pass these details to the templates that are processing the included
document, which you can do using the normal XSLT parameter passing
mechanisms.

> One area I defiantly got into trouble with my current success 
> is in regards to the namespace definitions. These included 
> documents have no use outside the parent document; so I guess 
> this error hasn't been found because the individual file was 
> not edited without the parent. 
> Anyway, there was some change tracking markup added via some 
> add/delete elements in a different namespace. Within the 
> parent the namespace was defined, but the included file 
> didn't have the declaration. When this file was passed to the 
> doc function it errored out because the namespace wasn't 
> defined in the included file.
> 
> I fixed this problem by correcting the included file, but if 
> I could have passed the context (in this case the namespace 
> information) I wouldn't have had a problem.

Documents included using XInclude have to be namespace well-formed in their
own right. If they aren't, then expect the tools to give you errors.

Michael Kay
http://www.saxonica.com/


Current Thread
Keywords