1

I am trying to replace the different status indicators (e.g. Y or N) of a column "Status_Ind" with images. I would like to create "traffic lights" where:
- "Completed" is replaced with /img/green.jpg
- "In Progress" is replaced with /img/yellow.jpg

Input XML:

<Rowsets>
  <Rowset>
    <Columns>
      <Column Description="Status_Ind"/>
      <Column Description="Name"/>
    </Columns>
    <Row>
      <Status_Ind>Completed</Status_Ind>
      <Name>TASK1</Name>
    </Row>
    <Row>
      <Status_Ind>In Progress</Status_Ind>
      <Name>TASK2</Name>
    </Row>
  </Rowset>
</Rowsets>  

For the XSLT, I am using the code in https://stackoverflow.com/a/8841189/1130511

My attempt:

<xsl:template match="@Description='Status_Ind']">
  <xsl:choose>
    <xsl:when test="Completed">
      <img src="../img/green.jpg" />
    </xsl:when>
    <xsl:when test="In Progress">
      <img src="../img/yellow.jpg" />
    </xsl:when>
  </xsl:choose>
</xsl:template>

1 Answer 1

4

Easy with two dedicated templates:

<xsl:template match="Status_Ind[. = 'Completed']">
  <img src="../img/green.jpg" />
</xsl:template>

<xsl:template match="Status_Ind[. = 'In Progress']">
  <img src="../img/yellow.jpg" />
</xsl:template>

This way you could simply do

<xsl:template match="Row">
  <tr>
    <td><xsl:apply-templates select="Status_Ind" /></td>
    <!-- etc -->
  </tr>
</xsl:template>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.