我有以下XSLT段可以正常工作。它根據@status varibale生成一個給定顏色的元素。使用xsl:選擇更新單個元素屬性
問題是它很不雅觀。我在每個xsl:when部分重複相同的值。
<xsl:template match="Task">
<xsl:choose>
<xsl:when test="@status = 'Completed'">
<task name="{@title}" processId="{@resourceId}" start="{@start}" end="{@end}" Id="{@id}" color="006d0f" borderColor="E1E1E1" />
</xsl:when>
<xsl:when test="@status = 'Failed'">
<task name="{@title}" processId="{@resourceId}" start="{@start}" end="{@end}" Id="{@id}" color="FF0000" borderColor="E1E1E1" />
</xsl:when>
<xsl:when test="@status = 'Risk'">
<task name="{@title}" processId="{@resourceId}" start="{@start}" end="{@end}" Id="{@id}" color="FF9900" borderColor="E1E1E1" />
</xsl:when>
<xsl:when test="@status = 'OnGoing'">
<task name="{@title}" processId="{@resourceId}" start="{@start}" end="{@end}" Id="{@id}" color="14f824" borderColor="E1E1E1" />
</xsl:when>
<xsl:otherwise>
<task name="{@title}" processId="{@resourceId}" start="{@start}" end="{@end}" Id="{@id}" color="e8e8e8" borderColor="E1E1E1" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
正如你所看到的就是變化是顏色屬性的唯一的事。
有沒有辦法讓我有一個單一的任務元素,並有xsl:選擇只更新顏色屬性?
在此先感謝...
非常感謝!這正是我需要的。 –