Re: [xsl] importing/including a stylesheet with a dynamic name (can't)

Subject: Re: [xsl] importing/including a stylesheet with a dynamic name (can't)
From: Chris Gow <cgow@xxxxxxxxxxxxxxxxxx>
Date: Tue, 30 Jan 2001 11:38:06 -0500
Dunno if this is an option, but cocoon lets you change the stylesheet to be used.


At 07:59 AM 1/30/01 -0800, you wrote:
This list, and the various related sites are a wonderful reference,
and I am enjoying coming up to speed on XSL/XML, using Xalan and Tomcat to
invoke it.

It seems that there is no way to dynamically import or include another
stylesheet, unless one writes the calling stylesheet at runtime.
In the system I am working with I don't have any control over writing
the stylesheet at runtime, it is delivered statically, and transformation
occurs only once, so I can't write a sheet dynamically with the
different file references everytime a transform is requested.

More concretely, I am trying to create a sheet that uses a default
stylesheet for a portion of an HTML document, but I want that
portion to be able to be replaced by a user simply specifying
an alternate stylesheet source in the source XML of the translation.

In the sheet below, I want to replace defaultbody.xsl with a
user's defined user.xsl that redefines the headersection and
bodysection templates. (Perhaps I am still thinking like a C++ programmer
too much)

XML fragment could have:
or it could have

XSL fragment:
 <!-- if the stylesheet element of the input XML is null, use this
default -->
 <xsl:include href="defaultbody.xsl"/>

 <!-- o.w. CANT DO THIS, but I want to   -->
 <xsl:include href="$UserXSLDoc"/>

<xsl:template match="/">
            <TITLE>Blah blah</TITLE>
       <BODY BGCOLOR="#ffffff">

<xsl:call-template name="headersection"/>

<xsl:apply-templates select="bodysection"/>


Note that this cannot work for several reasons: <xsl:choose> <!-- no stylesheet specified, use ours --> <xsl:when test="/foo/bar/styleSheet=''"> <!-- emit the formatted rows of worklist info --> <xsl:apply-templates select="workList/workListItem"/> </xsl:when>

          <xsl:variable name="XSLURL">
               <xsl:value-of select="foo/bar/styleSheet"/>
           Use the sheet at <xsl:value-of select="$XSLURL"/>
            <xsl:value-of select="document($XSLURL)"/>

Regards and thanks:
    Joe Longo
    Software Generalist
    Nevada City, California

XSL-List info and archive:


"It is inhumane, in my opinion, to force people who have a genuine
 medical need for coffee to wait in line behind people who apparently
 view it as some kind of recreational activity."
                -- Dave Barry

Chris Gow                                           Digital Fairway Corporation
Software Engineer                                   180 Attwell Drive Suite 360
cgow@xxxxxxxxxxxxxxxxxx                             Etobicoke, ON M9W 6A9                       416.628.7534

XSL-List info and archive:

Current Thread