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

RE: use-when attribute?

Subject: RE: use-when attribute?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 17 Dec 2004 08:50:17 -0000
xsl use when
> I'm trying to understand the details of the use-when attribute in the 
> latest XSLT 2.0 draft.  Is the below a valid use?
> 
>    <xsl:import href="output-xhtml.xsl" 
> use-when="$output-format='xhtml'"/>

No, because there are no variables in scope for evaluating the use-when
expression.

If you want to do this kind of thing, then in Saxon you can do

<xsl:import href="..." 
     use-when="system-property('output.format')='xhtml'"/>

which will read the value of the Java system property output.format, which
can be set on the command line using -Doutput.format=xhtml, or from a Java
application using System.setProperty().

This mapping of XSLT system properties to Java system properties is of
course not defined in the XSLT spec (because it's platform-dependent), but
hopefully most XSLT 2.0 processors will provide some kind of mechanism for
setting system properties of your choice.

However, I'm not sure whether this is the right design for your problem. I
would be inclined to stick with the traditional approach: the
special-purpose stylesheet module (here, the XHTML output module) should
import the general-purpose module, not the other way around; and you then
decide which special-purpose module to use by using that as your entry point
to the transformation. 

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

> 
> I'm trying to work out this idea of mine of designing for multiple 
> output targets.
> 
> So what I want to do is is define an output-format parameter 
> in my main 
> stylesheet (as above).  Likewise, I'd have a parameter for input 
> format.  I then want to condition which drivers get imported based on 
> these parameters using the use-when attribute.
> 
> The main stylesheet would then get imported into other 
> stylesheets like:
> 
>    <xsl:import href="citeproc.xsl"/>
>    <xsl:template match="/">
>      <xsl:apply-imports>
>        <xsl:with-param name="output-format" select="xhtml" 
> tunnel="yes"/>
>      </xsl:apply-imports>
>      <html>
>        <head>
>          <title>Testing</title>
>        </head>
>        <body>
>          <div id="content">
>            <div id="main-content">
>              <xsl:apply-templates/>
>              <div id="bibliography">
>                <xsl:copy-of select="$formatted-biblist"/>
>              </div>
>            </div>
>          </div>
>        </body>
>      </html>
>    </xsl:template>
> 
> Do I have the right idea here?
> 
> Bruce

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.