Subject: Re: [xsl] question about test="total[. $lt$ 10] From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Sun, 4 Mar 2001 11:46:54 +0000 |
Hi Amy, > <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> The best advice that we can offer is to start using XSLT rather than this old Microsoft-specific version. Have a look at the MSXML FAQ at http://www.netcrucible.com/xslt/msxml-faq.htm for more details. As for your question, the XML for the order elements look like: <order> 2 <total>65 </total> </order> When an XSLT processor looks at this XML, it forms a node tree that looks like: +- (element) order +- (text) [NL]2[NL] +- (element) total | +- (text) 65[NL] +- (text) [NL] Where [NL] are line breaks. When you evaluate the 'value' of a node, you're actually looking at its string value. The string value of a node is made up by concatenating all the text node descendants of the node. So the string value of the 'total' element is '65[NL]' which evaluates to the number 65 when you try to compare it to another number, so expressions like: total[. < 20] works OK. The string value of the 'order' element is '[NL]2[NL]65[NL]' which evaluates to NaN when you try to compare it to another number. What you want as the 'value' of the 'order' element is the value of the first text node in the order element. You can get that with: text()[1] So, if the current node is the 'order' element (as it is in a template matching the 'order' element or within an xsl:for-each that operates over the 'order' elements), you can test its 'value' with: <xsl:choose> <xsl:when test="text()[1] < 10"> <hr style="color:red" /> </xsl:when> <xsl:when test="text()[1] < 20"> <hr style="color:pink" /> </xsl:when> <xsl:otherwise> <hr style="color:green" /> </xsl:otherwise> </xsl:choose> Having to use text()[1] is one of the reasons that people who use XSLT usually encourage XML designers not to use mixed content. If your XML looked like: <order> <value>2</value> <total>65</total> </order> then you could use: value < 20 which is a bit neater. I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] question about test="total[. , caihongshui | Thread | RE: [xsl] xbind:module == xsl:scrip, Kaganovich, Yevgeniy |
Re: [xsl] Fw: repeat: XSLT 2.0 Req:, Jeni Tennison | Date | Re: [xsl] Selecting /getting only o, Jeni Tennison |
Month |