Jump to content

How do I use xsl:choose in XSL document?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
system32

system32

    Newbie

  • Members
  • PipPip
  • 24 posts
In my XML document I have:

<medications>
  <medication>
    <DIN>98765421</DIN>
    <brandName registered="generic">RossValve</brandName>
    <image>aorticValve.jpg</image>
    <category>heart valve</category>
    <units>each</units>
    <concentration>n/a</concentration>
  </medication>

  <medication>
    <DIN>00559407</DIN>
    <brandName registered="McNeil">Tylenol</brandName>
    <image>Tylenol.jpg</image>
    <category>pain relief</category>
    <units>tablets</units>
    <concentration>500mg</concentration>
  </medication>
</medications>
In my XSLT document I want to make it so that when the brandName attribute registered is = generic to show the brandName in bold and anything else in red color.

How can I do this?

Thank You

Edited by system32, 25 September 2010 - 10:36 AM.


#2
system32

system32

    Newbie

  • Members
  • PipPip
  • 24 posts
I think I got it :)

  <xsl:template match="brandName">
    <xsl:choose>
      <xsl:when test="./@registered = 'generic'">
        <b>
          <xsl:value-of select="."/>
        </b>
      </xsl:when>
      <xsl:otherwise>
        <span style="color:red">
          <xsl:value-of select="."/>
        </span>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users