?
Solved

XSL if test syntax

Posted on 2003-03-27
5
Medium Priority
?
484 Views
Last Modified: 2006-11-17
I want to test whether the value of my ID attribute is negative.  When it's negative, I want to output an 'm', otherwise output nothing.

Example of the xml:
<item ID="-1" /><item ID="3" />

At the moment the XSL I have includes:
<xsl:template match="@ID">
   <xsl:if test="@ID[ .$lt$ 0]">m</xsl:if>
</xsl:template>

At the moment the test is always failing, even when the ID is negative.
I'm not using the current w3 recommendation for xsl, but rather the working draft.

thanks for any light you can shed on this.
0
Comment
Question by:expert_intern
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Expert Comment

by:metalmickey
ID: 8223804
Its not a very technical solution as im not a very technical person but could you use something along then lines of..

<xsl:choose>
<xsl:when test="starts-with(@ID, '-')">
m
</xsl:when>
<xsl:otherwise />
</xsl:choose>

Ive not tried it but you could test for the presence of a - (minus sign) rather than testing whether the value is less than 0.

HTH

METALMICKEY
0
 
LVL 9

Accepted Solution

by:
sparkplug earned 320 total points
ID: 8223876
Hi,

The problem is not with the expression but the context. The expression would work in an "item" template as follows:

<xsl:template match="item">
  <xsl:if test="@ID[ .$lt$ 0]">m</xsl:if>
</xsl:template>

Change it as follows so that it works within a "@ID" template:

<xsl:template match="@ID">
  <xsl:if test=".[ .$lt$ 0]">m</xsl:if>
</xsl:template>


>S'Plug<
0
 
LVL 1

Expert Comment

by:foxyshadis
ID: 8228631
A better option is simply:

<xsl:template match="@ID">
 <xsl:if test=".$lt$ 0">m</xsl:if>
</xsl:template>
0
 
LVL 6

Expert Comment

by:pkaleda
ID: 8234140
Within your xsl template area you can post:

<xsl:choose>

        <xsl:when test="@ID &lt; 0">m</xsl:when>
        <xsl:otherwise></xsl:otherwise>
</xsl:choose>

Here is a working example from one of my pages.  It checks to see if the stock change is negative.  If so it changes teh font to red and displays the change value.  If itis 0 it displays the font as black.  Otherwise (meaning positive change) it displayse it green.

<xsl:choose>

<xsl:when test="change &lt; 0"><font color='red'><xsl:value-of select="change" /></font></xsl:when>

<xsl:when test="change = 0"><font color='000000'><xsl:value-of select="change" /></font></xsl:when>

<xsl:otherwise><font color='008000'><xsl:value-of select="change" /></font></xsl:otherwise>

</xsl:choose>

You can see it at http://wizard.ozsoft.com/newshist/index.asp

Hope this works.

pkaleda











0
 

Author Comment

by:expert_intern
ID: 8242385
thanks sparkplug
0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month7 days, 20 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question