XSL Template - reducing replication

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-03-15T10:39:01Z Indexed on 2010/03/15 10:59 UTC
Read the original article Hit count: 332

Filed under:
|
|
|

Hey

Sorry about the extremely vague question title (any suggestions for improvements welcome)

I have an XSL document that, currently, has lots of replication that I want to reduce.

Here is the following XML snippet I am working with

<Unit Status="alive"> 

I am currently using the following XSL to show images based on the status of the Unit

  <xsl:choose>
    <xsl:when test="@Status = 'alive'">
      <img src="/web/resources/graphics/accept.png" />
    </xsl:when>
    <xsl:when test="@Status = 'missingUnit'">
      <img src="/web/resources/graphics/error.png" />
    </xsl:when>
    <xsl:when test="@Status = 'missingNode'">
      <img src="/web/resources/graphics/exclamation.png" />
    </xsl:when>
    <xsl:when test="@Status = 'unexpectedUnit'">
      <img src="/web/resources/graphics/exclamation_blue.png" />
    </xsl:when>
    <xsl:otherwise>
      <!-- Should never get here -->
      <img src="/web/resources/graphics/delete.png" />
    </xsl:otherwise>
  </xsl:choose>

How do I put this code in a template or stylesheet that will allow me to stop copying / pasting this everywhere.

Thanks

© Stack Overflow or respective owner

Related posts about xslt

Related posts about xsl