Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check values in XML/XSL using choose/when

Status
Not open for further replies.

codedomino

Programmer
Apr 16, 2002
2
US
I want to check to see what the value in a column is and produce some xsl code based on that value.

I am using the following xsl:choose/when :

<xsl:choose>
<xsl:when test=&quot;entrydata[@columnnumber='0']/text/text()&quot;>
<xsl:choose>
<xsl:when test=&quot;entrydata[@columnnumber='0']/text = '0&quot;> <- errors out here in browser
<xsl:element name=&quot;img&quot;>
<xsl:attribute name=&quot;src&quot;>rejected.gif</xsl:attribute>
<xsl:attribute name=&quot;alt&quot;>Rejected</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test=&quot;entrydata[@columnnumber='0']/text = '1'&quot;>
<xsl:element name=&quot;img&quot;>
<xsl:attribute name=&quot;src&quot;>accepted.gif</xsl:attribute>
<xsl:attribute name=&quot;alt&quot;>Accepted</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:eek:therwise>
<xsl:element name=&quot;img&quot;>
<xsl:attribute name=&quot;src&quot;>inactivated.gif</xsl:attribute>
<xsl:attribute name=&quot;alt&quot;>Inactivated</xsl:attribute>
</xsl:element>
</xsl:eek:therwise>
</xsl:choose>
</xsl:when>
<xsl:eek:therwise>
<xsl:element name=&quot;img&quot;>
<xsl:attribute name=&quot;src&quot;>ecblank.gif</xsl:attribute>
<xsl:attribute name=&quot;height&quot;>1</xsl:attribute>
<xsl:attribute name=&quot;width&quot;>1</xsl:attribute>
<xsl:attribute name=&quot;alt&quot; />
</xsl:element>
</xsl:eek:therwise>
</xsl:choose>

Here is a sample of the xml it is working against:

<entrydata columnnumber=&quot;0&quot; name=&quot;Status&quot;>
<text>1</text>
</entrydata>


The possible values are null, 1, and 2. and depending on the value I want to show a different icon.

I have gone over some books, w3c.org, xml.com and others and cannot find how to do this. Any help would be appreciated.
 
Well, I am acutally able to answer my own question after some trail and error (blind luck).

The following line above:

<xsl:when test=&quot;entrydata[@columnnumber='0']/text = '0&quot;>

Should be like this:

<xsl:when test=&quot;entrydata[@columnnumber='0']/text[text()='0'&quot;>

and the other two lines that are just like it should be changed in the same manner.

Don't know if this will help anyone else, but just in case I thought I would post the solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top