2012-01-23 24 views
1

我試圖用圖像替換列「Status_Ind」的不同狀態指示符(例如Y或N)。我想創建「交通燈」,其中:
- 「完成」替換爲/img/green.jpg
- 「進行中」被替換爲/img/yellow.jpgXSLT +將字符串替換爲選定列中的圖像

輸入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> 

對於XSLT,我使用的代碼https://stackoverflow.com/a/8841189/1130511

我嘗試:

<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> 

回答

4

易與兩個專用模板:

<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> 

這樣,你可以簡單地做

<xsl:template match="Row"> 
    <tr> 
    <td><xsl:apply-templates select="Status_Ind" /></td> 
    <!-- etc --> 
    </tr> 
</xsl:template>