gpt4 book ai didi

xslt - 使用xsl :choose for updating a single element attribute

转载 作者:行者123 更新时间:2023-12-02 10:10:17 24 4
gpt4 key购买 nike

我有以下运行良好的 XSLT 段。它根据@status varibale生成具有给定颜色的元素。

问题是这样很不优雅。我在每个 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:choose 仅​​更新颜色属性?

提前致谢...

最佳答案

您可以移动choose里面task元素,并使用 <xsl:attribute> 创建该属性节点:

  <task name="{@title}"  processId="{@resourceId}" start="{@start}" end="{@end}" Id="{@id}" borderColor="E1E1E1">
<xsl:choose>
<xsl:when test="@status = 'Completed'">
<xsl:attribute name="color">006d0f</xsl:attribute>
</xsl:when>
<xsl:when test="@status = 'Failed'">
<xsl:attribute name="color">FF0000</xsl:attribute>
</xsl:when>
<xsl:when test="@status = 'Risk'">
<xsl:attribute name="color">FF9900</xsl:attribute>
</xsl:when>
<!-- etc. etc. -->
</xsl:choose>
</task>

关于xslt - 使用xsl :choose for updating a single element attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17855758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com