[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: xsl, and different xml versions

Subject: RE: xsl, and different xml versions
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 15 Apr 2005 09:43:31 +0100
result document saxon
> Hi all
> 
> I have a problem and I am unsure which approach to take in order to 
> solve it. The problem is this:
> 
> The root element of the xml I am transforming with xsl will have a 
> version number in it, indicating which version of the xsl i want to 
> transform it with. By that, I mean I have 2 style sheets, 
> both operating 
> on similer xml. I though I may be able to do this by xsl:import,

The stylesheet is always built and compiled before looking at the contents
of the source document, so this approach is doomed to fail.

You have two choices. 

First approach is to combine the two stylesheets into one, distinguishing
the two cases by use of modes.

Second approach is to have a piece of logic that examines the source
document and decides which of two stylesheets to apply based on the content
of the document.

I think the second solution is probably cleaner (more modular), though it
may mean writing a bit of logic in a language other than XSLT. (If you're
doing a lot of this kind of thing, I would thoroughly recommend using a
pipeline processing language such as Orbeon's XPL, but that would be OTT for
this problem on its own.) Depending on your environment you could write the
control logic in Javascript or Java. You could also do it entirely with XSLT
using Saxon's next-in-chain extension:

<xsl:template match="/">
<xsl:choose xmlns:saxon="http://saxon.sf.net/">
  <xsl:when test="*/@version='1'">
    <xsl:result-document saxon:next-in-chain="stylesheet1.xsl">
       <xsl:copy-of select="."/>
    </xsl:result-document>
  </xsl:when>
  <xsl:when test="*/@version='2'">
    <xsl:result-document saxon:next-in-chain="stylesheet2.xsl">
       <xsl:copy-of select="."/>
    </xsl:result-document>
  </xsl:when>
</xsl:choose>
</xsl:template>

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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.