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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

value-of in If/Choose statements?

Status
Not open for further replies.

jfrost10

Programmer
Jun 3, 2001
2,004
CA
Hey guys,

Here's what I'm trying to do: only execute code when the value of an item isn't an empty string. Tell me what looks wrong:

XML:
<Item>Item1</Item>
<Item>Item2</Item>
<Item></Item>
<Item>Item3</Item>

XSL:
<xsl:template match=&quot;Item&quot;>

<xsl:for-each select=&quot;.&quot;>

<xsl:if test=&quot;value-of select='Item' != ''&quot;>
DO STUFF HERE
</xsl:if>

</xsl:for-each>

</xsl:template>

I'm pretty sure the way I'm trying to get the value fromthe current node is wrong in the if, but I'm not sure what it should be.

Thanks,

Jack
 

1st, You may have mistyped this..
<xsl:if test=&quot;value-of select='Item' != ''&quot;>
should be
...select=&quot;Item !=...


2nd, you may want to use normalize-space() to avoid blank strings

3rd, you can avoid the look with...
<xsl:apply-templates select=&quot;Item[normalize-space()]&quot; >
in some controlling template and simplifying the Item template
<xsl:template match=&quot;Item&quot;>
DO STUFF HERE
</xsl:template>

 
1st: so having double quotes within double quotes won't screw up the compiler?

2nd: whats normalize-space?

3rd: I'm sure that will make more sense once I know what normalize-space means
;)

Thanks for the post.

jack
 
Peako:

I'm still having problems getting this to work. here's my line:

<xsl:when test=&quot;value-of select=&quot;ForYourApproval!='x'&quot;&quot;>

(using a choose now, not an if)
What should the correct syntax for this be to get it to work?

Thanks

jack
 
Hey Jack,
what about:

<xsl:when test=&quot;string(child::ForYourApproval)!='x'&quot;>

Look at the string functions you can use with XSLT.
Try:

HTH [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top