[Home] [By Thread] [By Date] [Recent Entries]
At 2009-05-15 19:36 -0400, Matthew L. Avizinis wrote:
Despite my slight embarrassment earlier, dare I ask a further question for my own curiosity please? Suppose (I'm not saying OPs data could ever fit this condition) instead of <FAULT-REF FAULTS="PF01 PF02 PF03 PF04 PF05 PF06 PF07 PF08 PF09 PF10 PF11"/> you had <FAULT-REF FAULTS=" "/> or <FAULT-REF FAULTS=""/>. Very valid point, Matthew ... my solution falls apart. Well spotted. Would you change the templates at all? If so, how? I would wrap the initial call with a single <xsl:if> so as to introduce a single test regardless of the number of tokens rather than introduce any test in the template that would be repeated when not necessary: <xsl:template match="FAULT-REF">
<xsl:if test="normalize-space(@FAULTS)">
<xsl:call-template name="do-tokens">
<xsl:with-param name="string"
select="concat(normalize-space(@FAULTS),' ')"/>
</xsl:call-template>
</xsl:if>
</xsl:template><xsl:template name="do-tokens">
<xsl:param name="string"/>
<xsl:if test="contains($string,' ')">
<statemanipulation>
<variableref name="{substring-before($string,' ')}"/>
<fault fault-code="{substring-before($string,' ')}" fault-state="ok"/>
</statemanipulation>
<xsl:call-template name="do-tokens">
<xsl:with-param name="string" select="substring-after($string,' ')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>In this way I still have only a single test= in the loop, and I only call the loop if I know I have some tokens. Thank you for bringing light to this. . . . . . . . . . . . Ken
|

Cart



