RE: [xsl] sorting

Subject: RE: [xsl] sorting
From: Krithiga Subramanian <krithiga_s@xxxxxxxx>
Date: Fri, 5 Jan 2001 16:57:48 +0530
Thanks Jeni

Apprecitae your response


-----Original Message-----
From: Jeni Tennison [mailto:mail@xxxxxxxxxxxxxxxx]
Sent: Friday, January 05, 2001 4:17 PM
To: Krithiga Subramanian
Cc: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: Re: [xsl] sorting

Hi Krithiga,

> I output the HTML to loop thru each x.

I take it you mean you're using xsl:for-each to iterate:

<xsl:for-each select="x">

> But i have to create a text box if the value of col in x is < 2 ,
> i.e only in case where x has id=2 and only 1 col

I'm a bit confused about what you want to test exactly. You want to
test whether the value of the 'col' element (which is a child of 'x'
is less than 2. Within the xsl:for-each, the current node is the 'x'
element. So, to get the value of its col child, you need the XPath:


or, as child:: is the default axis, simply:


To test whether this is less than 2, you can use:

  col &lt; 2

This tests whether *any* of the col children of the x element have a
value less than 2.  If you want to test whether *all* of the col
children of the x element have values less than 2, then you have to
turn it around and ask whether it's *not* the case that *any* of the
col children of the x element have values *greater than or equal to*

  not(col &gt;= 2)

If you want to test how many col children an 'x' element has, then use
the count() function to count them:


So if you want to see whether it only has one col, then use:

  count(col) = 1

If you want to test whether the id attribute of the 'x' element is
equal to '2', then use:

  @id = 2

You can combine the tests together with 'and' and 'or'.  For example,
if you want to test whether there's only one col and that col has a
value less than 2, then use:

  count(col) = 1 and col &lt; 2

To do something conditionally within the xsl:for-each, and given that
you'll be doing something else with other 'x' elements, you need

    <xsl:when test="...your condition...">
      <!-- create the text box -->
      <!-- do whatever you do usually -->

An alternative is to use xsl:apply-templates rather than xsl:for-each
and have templates for the different kinds of 'x' elements:

  <xsl:apply-templates select="x" />

... later in the stylesheet ...

<xsl:template match="x">
  <!-- do whatever you do usually -->

<xsl:template match="x[...your condition...]">
  <!-- create the text box -->

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread