Avatar of Larry Brister
Larry Brister
Flag 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?
XML.NET ProgrammingMicrosoft Development

Avatar of undefined
Last Comment
Gertone (Geert Bormans)

8/22/2022 - Mon
Gertone (Geert Bormans)

<xsl:if test="normalize-space(LicenseExpirationMonth1)"><xsl:text>/</xsl:text></xsl:if>
ASKER CERTIFIED SOLUTION
zc2

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Larry Brister

ASKER
Perfect!

Remind me to buy you a sody-pop sometime!
Gertone (Geert Bormans)

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)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Larry Brister

ASKER
Gertone...
Sorry.  Didn;t see your reply for some reason.  My apologies.
Gertone (Geert Bormans)

Ah, I did not spot the second value-of, good catch zc2
Gertone (Geert Bormans)

@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 :-)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.