|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








