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

Subject: [xsl] importing/including a stylesheet with a dynamic name (can't)
From: "Joe Longo" <joe@xxxxxxxxxxx>
Date: Tue, 30 Jan 2001 07:59:41 -0800
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:
     <!-- 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: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:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread