Re: [xsl] processing multiple values in a single attribute

Subject: Re: [xsl] processing multiple values in a single attribute
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 15 May 2009 20:32:00 -0400
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


-- XSLT/XSL-FO/XQuery hands-on training - Los Angeles, USA 2009-06-08 Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread