Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

XSL if test syntax

Posted on 2003-03-27
5
Medium Priority
?
488 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

571 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