This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: sorting
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] sorting
- From: Krithiga Subramanian <krithiga_s at infy dot com>
- Date: Fri, 5 Jan 2001 16:57:48 +0530
- Reply-To: xsl-list at lists dot mulberrytech dot com
Thanks Jeni
Apprecitae your response
/k
-----Original Message-----
From: Jeni Tennison [mailto:mail@jenitennison.com]
Sent: Friday, January 05, 2001 4:17 PM
To: Krithiga Subramanian
Cc: 'xsl-list@lists.mulberrytech.com'
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">
...
</xsl:for-each>
> 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:
child::col
or, as child:: is the default axis, simply:
col
To test whether this is less than 2, you can use:
col < 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*
2:
not(col >= 2)
If you want to test how many col children an 'x' element has, then use
the count() function to count them:
count(col)
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 < 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:choose:
<xsl:choose>
<xsl:when test="...your condition...">
<!-- create the text box -->
</xsl:when>
<xsl:otherwise>
<!-- do whatever you do usually -->
</xsl:otherwise>
</xsl:choose>
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>
<xsl:template match="x[...your condition...]">
<!-- create the text box -->
</xsl:template>
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list