[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: Mike Brown <mike@xxxxxxxx>
Date: Wed, 26 Feb 2003 06:03:52 -0700 (MST)
xsl external file
Anders Svensson wrote:
> 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...

You still have a condition, somehow expressed in this external file, that
indicates either specifically what you want to ignore in the source tree, or
just the fact that you want to ignore something, correct? But the ignorable 
elements may be scattered throughout the source tree, right?

I suggest that you "filter out" not necessarily by trying to avoid selecting
certain nodes for processing, but by walking the tree as normal (e.g. with the
built-in templates), and each time you encounter an element, you decide
whether or not it is ignorable. Since variable references aren't allowed in
match patterns, you have to perform the test inside each template.

For example (untested):

<ignore>
  <element name="ELEMENT">
    <attr name="Help" value="Yes"/>
  </element>
</ignore>

Then your stylesheet could be something like...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name="elementsToIgnore" select="document('ignore.xml')/ignore/element"/>

<!--
  this template
  produces a result tree fragment containing some string 
  data if the given element is ignorable
-->
<xsl:template name="checkElement">
  <xsl:param name="thisElement" select="."/>
  <xsl:variable name="ignorableElemsToTest" select="$elementsToIgnore[@name=$n]"/>
  <xsl:for-each select="$ignorableElemsToTest">
    <xsl:for-each select="attr">
      <xsl:if test="$thisElement/@*[name()=current()/@name]=current()/@value">1</xsl:if>
    </xsl:for-each>
  </xsl:for-each>
</xsl:template>

<xsl:template match="ELEMENT">
  <xsl:variable name="thisElementIsIgnorable">
    <xsl:call-template name="checkElement"/>
  </xsl:variable>
  <xsl:if test="not(string($thisElementIsIgnorable))">
    <!-- this node is not ignorable today, so go ahead and generate some output -->
    <p>help text: <xsl:value-of select="."/></p>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

 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.