RE: if to separate child elements

Subject: RE: if to separate child elements
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Tue, 26 Sep 2000 10:46:40 +0100
>  I am somehow really stuck trying to separate out different child
> elements using <xsl:if>. Please help with the following situation if
> possible:
> I am trying:
> 
> <xsl:for-each select="help/helptext|help/helpexample">
> <xsl:if test="helptext"/>

Firstly, the xsl:if should be closed with ">" not "/>": an xsl:if with no
content is meaningless, since it does nothing, whether or not the condition
is true.

Secondly, if you want to test whether the element you are processing is a
helptext element, use <xsl:if test="self::helptext">. The way you've written
the test, you are testing whether the current element has a helptext child.

Thirdly, the best way of doing this kind of processing is to use
<xsl:apply-templates> and template rules, rather than xsl:for-each and
xsl:if.

> <xsl:if test="position() mod 2=0">
> the position() mod 2 part works, but I dont have any 
> guarantee that the
> particular element will always be in the even position.

If the elements won't always be in the even position, then I fail to see why
you are testing to see if the element is in an even position, and I don't
understand what you mean by saying it "works". Presumably you mean that it
sometimes gives the right answer... 

Mike Kay 


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


Current Thread