|
Subject:
|
conditional xsl:import ?
|
|
Posted By:
|
TPP
|
Post Date:
|
5/16/2006 3:15:55 AM
|
Hi.Is it possible to dosomething like this:
I recive an xml which can have 14 different structures. Structure version is defined in a first node of xml. I immagined to do a "master" xslt file with case clause which would decide on a "xml structure version node" which "slave" xslt to use. I thougt to use imports but xsl:apply-imports does not accepts any Attributes (such as filename :) )
thanks for help, peter 
|
|
Reply By:
|
mhkay
|
Reply Date:
|
5/16/2006 3:32:38 AM
|
xsl:import is a compile-time facility, it can't be used for run-time branching or polymorphism. You could tackle this using modes. Write an xsl:choose which selects on the controlling node and does apply-templates in one of 14 different modes depending on its value. Alternatively, if you want to keep the code for the 14 cases completely separate (which sounds like a good thing to do), consider driving it from a controlling application, e.g. in Java. Build the tree to be transformed, peek into it using an XPath expression called from the Java code, then fire off one of 14 different stylesheets.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
TPP
|
Reply Date:
|
5/16/2006 4:32:17 AM
|
thank you for your reply... each of 14 types needs about 1000 lines or more of xslt code. Do you think its ok to put it in 14 templates inside one file ?
Controling this from a controlling app is not an option. I feed xslt and xml into existing app which is not to be edited.
Regards, Peter.
|
|
Reply By:
|
mhkay
|
Reply Date:
|
5/16/2006 5:18:18 AM
|
I would definitely keep the code for each document type in a separate stylesheet module (file). But unless you do the switching from an outside application, you will need to include or import all 14 files into your main module which does the run-time switching.
If you can't change the invoking application, you might be able to use extensions in your stylesheet to achieve the same effect. For example Saxon has an extension saxon:transform() that allows you to invoke one transformation dynamically from within another.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|