sqlpadawan
sqlpadawan

Reputation: 305

XSL variable assignment

I have another simple xsl variable question. I'm trying to evaluate an expression and toggle an 'AM' or 'PM' suffix. The variable never evaluates to anything. I've even changed my test to with no luck.

<xsl:variable name="DisplayAMPM">
  <xsl:choose>
    <xsl:when test="number(substring($LastBootUpTime, 9,2))>11">
      <xsl:value-of select="PM"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="AM"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:variable>
<xsl:copy-of select="DisplayAMPM"/>

Upvotes: 1

Views: 1067

Answers (2)

user268396
user268396

Reputation: 11976

You have a runaway > character in your test attribute which should of course be &gt;. Secondly, you don't copy your variable ($DisplayAMPM), instead you copy the (nonexistent?) DisplayAMPM element child node set.

Upvotes: 0

Daniel Haley
Daniel Haley

Reputation: 52858

If you use value-of, put the "AM" and "PM" in quotes so that the processor sees it as a string.

Also, if you reference the variable, like you're trying to do in the copy-of, don't forget the $.

<xsl:variable name="DisplayAMPM">
  <xsl:choose>
    <xsl:when test="number(substring($LastBootUpTime, 9,2))>11">
      <xsl:value-of select="'PM'"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="'AM'"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:variable>
<xsl:copy-of select="$DisplayAMPM"/>

Upvotes: 3

Related Questions