xsl-list
[Top] [All Lists]

RE: [xsl] Reusing templates and params

2008-05-14 06:23:09
I fear I must suffer the wrath of posting a full stylesheet but I can not find 
a way to both explain my problem and truncate the stylesheet to an acceptable 
size.

During the process of attempting to produce a reduced size, I believe I have 
identified two problem areas (both commented)

Running with "Problem area 1" and "Problem area 2" commented out, will produce 
what I'd expect to see but would want to produce all <Line>'s.

Running with "Problem area 2" and "Problem area 1" commented out, will produce 
all <Line>'s but not with the structured content inside the <Line> tag.

Running with both "Problem area's" causes the "hanging" issue.

Apologies again for the sizeable post but I can no longer see the woods for the 
trees.

## Start of Stylesheet ##

<xsl:variable name="testVar" 
select="'1,A,B,C&#13;&#10;2,A,B,C&#13;&#10;3,A,B,C'" />
  
  <xsl:template match="/">
    <myOutput>
        <xsl:call-template name="baseString">
          <xsl:with-param name="inputA" select="concat('&#13;',$testVar)" />
        </xsl:call-template>
    </myOutput>
  </xsl:template>

  <xsl:template name="baseString">
    <xsl:param name="inputA" />
    
    <xsl:if test="string-length($inputA) &gt; 0">
      <xsl:choose>
        <xsl:when test="substring($inputA,1,2)='&#13;&#10;'">
          <xsl:call-template name="readLine">
            <xsl:with-param name="inputLine" 
select="concat(',',substring($inputA,3))" />
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="substring($inputA,1,1)='&#13;'">
          <xsl:call-template name="readLine">
            <xsl:with-param name="inputLine" 
select="concat(',',substring($inputA,2))" />
          </xsl:call-template>
        </xsl:when>
      </xsl:choose>
    </xsl:if>
  </xsl:template>

  <xsl:template name="readLine">
    <xsl:param name="inputLine" />

    <xsl:if test="string-length($inputLine) &gt; 0">
      <Line>
        <xsl:choose>
          <xsl:when test="substring($inputLine,1,1)=','">
            <!-- Problem area 1 (Start)-->
            <xsl:call-template name="readValue">
              <xsl:with-param name="inputValue" 
select="substring($inputLine,2)" />
            </xsl:call-template>
            <!-- Problem area 1 (End)-->
          </xsl:when>
        </xsl:choose>
      </Line>

      <xsl:variable name="checkString">
        <xsl:call-template name="trimString">
          <xsl:with-param name="inputTrim" select="substring($inputLine,2)" />
          <xsl:with-param name="stopPoint" select="'Line'" />
        </xsl:call-template>
      </xsl:variable>

      <xsl:if test="string-length($checkString) &gt; 0">
        <xsl:if test="substring($checkString,1,1)='&#13;'">
          <!-- Problem area 2 (Start)-->
          <!--
          <xsl:call-template name="baseString">
            <xsl:with-param name="inputA" select="$checkString" />
          </xsl:call-template>-->
          <!-- Problem area 2 (End)-->
        </xsl:if>
      </xsl:if>
    </xsl:if>
    
  </xsl:template>

  <xsl:template name="readValue">
    <xsl:param name="inputValue" />

    <xsl:if test="string-length($inputValue) &gt; 0">
      <Value>
        <xsl:call-template name="readString">
          <xsl:with-param name="inputString" select="$inputValue" />
        </xsl:call-template>
      </Value>

      <xsl:variable name="checkString">
        <xsl:call-template name="trimString">
          <xsl:with-param name="inputTrim" select="$inputValue" />
        </xsl:call-template>
      </xsl:variable>

      <xsl:if test="string-length($checkString) &gt; 0">
        <xsl:choose>
          <xsl:when test="string-length($checkString) = 1">
            <xsl:value-of select="$checkString"/>
          </xsl:when>
          <xsl:when test="string-length($checkString) &gt; 1">
            <xsl:choose>
              <xsl:when test="substring($checkString,1,1)=','">
                <xsl:call-template name="readValue">
                  <xsl:with-param name="inputValue" 
select="substring($checkString,2)" />
                </xsl:call-template>
              </xsl:when>
            </xsl:choose>
          </xsl:when>
        </xsl:choose>
      </xsl:if>
      
    </xsl:if>
  </xsl:template>

  <xsl:template name="readString">
    <xsl:param name="inputString" />

    <xsl:choose>
      <xsl:when test="substring($inputString,1,1)=','" />
      <xsl:when test="substring($inputString,1,1)='&#13;'" />
      <xsl:otherwise>
        <xsl:value-of select="substring($inputString,1,1)"/>
        <xsl:call-template name="readString">
          <xsl:with-param name="inputString" select="substring($inputString,2)" 
/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="trimString">
    <xsl:param name="inputTrim" />
    <xsl:param name="stopPoint" />

    <xsl:choose>
      <xsl:when test="$stopPoint='Line'">

        <xsl:choose>
          <xsl:when test="string-length($inputTrim)=0">
            <xsl:value-of select="''"/>
          </xsl:when>
          <xsl:when test="substring($inputTrim,1,1)='&#13;'">
            <xsl:value-of select="$inputTrim"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="trimString">
              <xsl:with-param name="inputTrim" select="substring($inputTrim,2)" 
/>
              <xsl:with-param name="stopPoint" select="'Line'" />
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>

      </xsl:when>
      <xsl:otherwise>

        <xsl:choose>
          <xsl:when test="string-length($inputTrim)=0">
            <xsl:value-of select="''"/>
          </xsl:when>
          <xsl:when test="substring($inputTrim,1,1)=','">
            <xsl:value-of select="$inputTrim"/>
          </xsl:when>
          <xsl:when test="substring($inputTrim,1,1)='&#13;'">
            <xsl:value-of select="$inputTrim"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="trimString">
              <xsl:with-param name="inputTrim" select="substring($inputTrim,2)" 
/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>

      </xsl:otherwise>

    </xsl:choose>
  </xsl:template>

## End of Stylesheet ##

Carl


-----Original Message-----
From: David Carlisle [mailto:davidc(_at_)nag(_dot_)co(_dot_)uk]
Sent: 14 May 2008 12:02
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Reusing templates and params




The problem is it appears to hang, as if running in an endless loop.

so presumably one of the definitions that you didn't show is wrong so
that the test to terminate the recursion never ends the
recursion. Surely you can cut it down to a small two template stylesheet
that actually runs and demonstrates the problem.

David



________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



----------------------------------------------------------------
This e-mail (which includes any files attached to it) is not 
contractually binding on its own, it is intended solely for 
the named recipient and may contain CONFIDENTIAL, legally 
privileged or trade secret information protected by law. 
If you have received this message in error please delete it 
and notify us immediately by telephoning +44(0)2476421213. 
If you are not the intended recipient you must not use, disclose, 
distribute, reproduce, retransmit, retain or rely on any 
information contained in this e-mail. Please note that Severn 
Trent Laboratories Limited reserve the right to monitor email 
communications in accordance with applicable law and regulations.

To the extent permitted by law, neither Severn Trent Laboratories 
Limited or any of its subsidiaries, nor any employee, director 
or officer thereof, accepts any liability whatsoever in relation 
to this e-mail including liability arising from any external breach 
of security or confidentiality or for virus infection or for statements 
made by the sender as these are not necessarily made on behalf of 
Severn Trent Laboratories Limited.

Severn Trent Laboratories Limited is a limited company registered in 
England and Wales under registered number 2148934 with its registered 
office at 2297 Coventry Road, Birmingham B26 3PU. 
-----------------------------------------------------------------------

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--