Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

XSL choose or if??

I have the following tag which is fine when there's data

This:
<xsl:value-of select="LicenseExpirationMonth1"/>/<xsl:value-of select="LicenseExpirationYear1"/>

Produced (Example) this:
01/2014

However...when there's no data I get the / mark...which I don;t want.

How do I wrap that to only show the / when there's data?
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

<xsl:if test="normalize-space(LicenseExpirationMonth1)"><xsl:text>/</xsl:text></xsl:if>
ASKER CERTIFIED SOLUTION
Avatar of zc2
zc2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Larry Brister

ASKER

Perfect!

Remind me to buy you a sody-pop sometime!
some notes
- normalize-space() I do that to cast the element to string and remove trailing whitespace (basically I do this to make sure that a single space would still return fale)
- why not test="not(normalize-space(LicenseExpirationMonth1) = '')"> ? Well, a string expression used as a boolean expression returns false if the string expression resolves to an empty string
- why xsl:if and not xsl:choose? You would use xsl:choose when there are multiple conditional branches or if you would have an "else" clause (which would be xsl:otherwise in the choose)
<xsl:if test="..."></xsl:if> is short for
<xsl:choose><xsl:when test="..."></xsl:when></xsl:choose>
(or xsl:if is short for an xsl:choose with only one xsl:when and no xsl:otherwise)
Gertone...
Sorry.  Didn;t see your reply for some reason.  My apologies.
Ah, I did not spot the second value-of, good catch zc2
@Irbrister,
well, no problem,
though mine would have the desired effect (you likely don't want the '/' if the Month is not there and the year is) I consider zc2's solution more correct.
Most important is that you have an answer to your question :-)