Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 16th, 2006, 03:15 AM
TPP TPP is offline
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default conditional xsl:import ?

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 :)

 
Old May 16th, 2006, 03:32 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old May 16th, 2006, 04:32 AM
TPP TPP is offline
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old May 16th, 2006, 05:18 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional processing in XSL francislang XSLT 2 March 18th, 2008 12:04 AM
xsl import/include mapping sammyj727 XSLT 3 July 19th, 2007 04:15 PM
xsl:include / import and tomcat amitda XSLT 2 April 17th, 2007 10:37 AM
Problems using <xsl:import in web app flanagaj XSLT 0 April 18th, 2006 08:40 AM
xsl:import or xsl:include ShaileshShinde XSLT 2 August 17th, 2005 04:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.