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

RE: Get value from external file

Subject: RE: Get value from external file
From: "Anders Svensson" <anders.svensson@xxxxxxxxxxx>
Date: Wed, 26 Feb 2003 10:09:54 +0100
xsl external file
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...

Regards,
Anders

-----Original Message-----
From: Mike Brown [mailto:mike@xxxxxxxx]
Sent: den 26 februari 2003 00:11
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  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 
dyn:evaluate())?

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

<info>
  <profile>help</profile>
</info>

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:choose>
    <xsl:when test="$profile='help'">
      <xsl:apply-templates mode="help"/>
    </xsl:when>
    <xsl:when test="$profile='apidocs'">
      <xsl:apply-templates mode="apidocs"/>
    </xsl:when>
    <xsl:when test="$profile='mktg'">
      <xsl:apply-templates mode="mktg"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:message>unknown profile '<xsl:value-of select="$profile"/>'</xsl:message>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!--
  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>

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

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

Mike

-- 
  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/xml/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.