Subject: RE: [xsl] Get value from external file From: "Anders Svensson" <anders.svensson@xxxxxxxxxxx> Date: Wed, 26 Feb 2003 14:50:00 +0100 |
Wow... I just barely understand it, but it seems to work! Just a couple of questions In the following statement: <xsl:variable name="ignorableElemsToTest" select="$elementsToIgnore[@name=$n]"/> I removed the test [@name=$n] I didn't understand what it was for, there wasn't any variable named n...and as long as I had reversed the values (testing for the element with an attribute value of "No") it works. But did I miss something there? Also, I guess this statement <xsl:if test="$thisElement/@*[name()=current()/@name]=current()/@value">1</xsl:if> coupled with this statement <xsl:if test="not(string($thisElementIsIgnorable))"> checks for the value 1 (sort of boolean?) or not. But if so, why is the string function used? Shouldn't one need some sort of numerical value? Like I said, it works, I just want to understand why :-) Thanks! /Anders -----Original Message----- From: Mike Brown [mailto:mike@xxxxxxxx] Sent: den 26 februari 2003 14:04 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Get value from 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 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Get value from external f, Mike Brown | Thread | Re: [xsl] Get value from external f, Mike Brown |
RE: [xsl] Re: Re: The Perils of Sud, Dimitre Novatchev | Date | [xsl] xsl:element and namespace out, ETarlton |
Month |