2013-07-25 2 views
3

잘 작동하는 다음 XSLT 세그먼트가 있습니다. @status varibale에 따라 주어진 색상의 요소를 생성합니다.xsl 사용 : 단일 요소 특성 업데이트를 선택하십시오.

문제는 매우 비현실적입니다. 모든 xsl : 섹션에서 같은 값을 반복합니다.

<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 : color 속성 만 업데이트 할 수있는 방법이 있습니까? 하나 개의 속성 노드가 <xsl:attribute>를 사용하여 그냥 사전에

감사합니다 ...

답변

3

당신은 task 요소 내부의 choose를 이동하고 만들 수 있습니다 더 나은

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

고마워! 그게 내가 필요한거야. –

3

:

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

+1 : 내 뇌가 어떤 이유로 든 마지막 도약을하지 못했습니다. :) –