RE: [xsl] Get value from external file

Subject: RE: [xsl] Get value from external file
From: "Anders Svensson" <anders.svensson@xxxxxxxxxxx>
Date: Wed, 26 Feb 2003 10:09:54 +0100
Mike, you're absolutely right, I meant to use the variable in the expression (it was late my time...:-)
So it should have been:

> In the xsl file:
> <xsl:param name="varValue" select="document('varValue.xml')/varValueElement"/>
> <xsl:apply-templates select="$varValue/>

I'm not sure what the foo:evaluate thing does, I have to read about that. However, your suggestion with the modes was interesting, but I'm not sure it works for me, if I understand you correctly. As I see the example you wrote, it is a way to process the element differently depending on the profile. But I do not want to process the element differently at any time, all I want to do is to "filter out" all <ELEMENT> that don't have the attribute "Help='Yes'" (for instance). So I really don't want to have a set of four or five templates for the same element (one for each mode) when they are exactly the same...


-----Original Message-----
From: Mike Brown [mailto:mike@xxxxxxxx]
Sent: den 26 februari 2003 00:11
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Get value from external file

Anders Svensson wrote:
> I have an xsl file which formats xml files into html, online help etc, and
> the xml has attributes at certain elements to "profile" the documents into
> different versions (different formats, users, etc). The xsl creates the
> profiled versions by selecting elements by their profile attributes. For
> example an element can look like this:
> <ELEMENT Help='Yes'>
> The xsl can then select these particular elements by select statements such
> as <xsl:apply-templates select="ELEMENT[Help='Yes']/>.
> BUT, and here's the question: I need to be able to place the profiling
> select value in a separate file so I can keep the xsl intact, rather than
> changing it for each version transformation. That way I only need to change
> the (xml)file containing the value, and fetch it using a variable. (E.g.)
> I would like to be able to do something like this:
> xml document containing the value:
> <varValueElement>ELEMENT[Help='Yes']</varValueElement>

You probably meant ELEMENT[@Help='Yes'] because you are talking about the 
attribute named Help, not the child element named Help.
> In the xsl file:
> <xsl:param name="varValue" select="document('varValue.xml')/varValueElement"/>
> <xsl:apply-templates select="ELEMENT[Help='Yes']/>

What are you trying to do here? Setting $varValue has no bearing on the
behavior of that paticular apply-templates instruction. Perhaps you meant
something like

  <xsl:apply-templates select="foo:evaluate($varValue)"/>

where foo is a prefix bound to the namespace for an extension function for 
dynamic evaluation of strings as XPath expressions (e.g., EXSLT's 

I would approach the problem differently, though. Have a control.xml that
says what profile to generate:


Then in your stylesheet go get that data, and make a pass through the
source tree using a mode depending on what it was:

<xsl:template match="/">
  <xsl:variable name="profile" select="document('control.xml')/info/profile"/>
    <xsl:when test="$profile='help'">
      <xsl:apply-templates mode="help"/>
    <xsl:when test="$profile='apidocs'">
      <xsl:apply-templates mode="apidocs"/>
    <xsl:when test="$profile='mktg'">
      <xsl:apply-templates mode="mktg"/>
      <xsl:message>unknown profile '<xsl:value-of select="$profile"/>'</xsl:message>

  note: there are built-in templates matching "*" for
  each mode; they just contain the instruction
    <xsl:apply-templates mode="(the same mode"/>,
  resulting in the selection and processing of that
  element's children.

<xsl:template match="ELEMENT[@Help='Yes']" mode="help">

<xsl:template match="ELEMENT[@APIDocs='Yes']" mode="apidocs">

<xsl:template match="ELEMENT[@MarketingDrivel='Yes']" mode="mktg">


  Mike J. Brown   |
  Denver, CO, USA |

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread