xsl-list
[Top] [All Lists]

Re: select element based on value of one of the children

2005-10-11 02:37:37
Hi again,

From Geert's reply, I came to think that there are two ways of doing
this. One is to select only those elements where the condition is
true, the other is to match only those where the condition is true
(the latter requires a template based approach, of course).

Either you can select the nodeset like:
<xsl:apply-templates select="a[b='7']"/>

<xsl:template match="a">
..
</template>

Here you would usually have a mode on the template so that the
template does not get accidently invoked with other a elements.

Here, you can also use a for-each loop:
<xsl:for-each select="a[b='7']">
..
</xsl:for-each>


The other one is to be used if you want to do different things
depending on the value.
<xsl:apply-templates select="a"/>

<xsl:template match="a">
  <!-- Default matching a elements. Will be invoked if no template
matches overrule this one -->
..
</xsl:template>

<xsl:template match="a[b='7']">
  <!-- This template will overrule the more general one, provided that
the predicate is true (that the child element b has a string value of
'7') -->
..
</xsl:template>

Regards,
Ragulf Pickaxe :-)

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>