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
you had

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:template name="do-tokens">
  <xsl:param name="string"/>
  <xsl:if test="contains($string,' ')">
      <variableref name="{substring-before($string,' ')}"/>
       <fault fault-code="{substring-before($string,' ')}" fault-state="ok"/>
    <xsl:call-template name="do-tokens">
      <xsl:with-param name="string" select="substring-after($string,' ')"/>

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. Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: Video overview: G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 Legal business disclaimers:

Current Thread