You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Michael Giroux <ml...@gmail.com> on 2006/12/08 18:41:35 UTC

Invalid use of string utils in

Following is an excerpt from $ANT_HOME/etc/junit-noframes.xsl.

<!--
    template that will convert a carriage return into a br tag
    @param word the text from which to convert CR to BR tag
-->
<xsl:template name="br-replace">
    <xsl:param name="word"/>
    <xsl:param name="br"><br/></xsl:param>
    <xsl:value-of select='stringutils:replace(string($word),"&#xA;",$br)'/>
</xsl:template>

The purpose of the template is to convert new-lines to <br/> tags in text
such as stack traces. This template does not insert the desired <br/> tags
and only deletes the new-lines that are found.

I chased this for a week in the XALAN mailing list to learn that this is not
valid.

I was able to accomplish the desired effect (preserving formatting of the
stack trace) by adding <pre> ... </pre>  tags to the generated HTML and
removing the call to the br-replace template.  My solution is shown below.

Perhaps someone on the dev team could consider this for ANT 1.7?

Michael Giroux

<!-- Style for the error and failure in the tescase template -->
<xsl:template name="display-failures">
    <xsl:choose>
        <xsl:when test="not(@message)">N/A</xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="@message"/>
        </xsl:otherwise>
    </xsl:choose>
    <!-- display the stacktrace -->
*    <pre>*
    <code>
        <br/>
        <xsl:value-of select="." />
*        <!--
        <xsl:call-template name="br-replace">
            <xsl:with-param name="word" select="."/>
        </xsl:call-template>
         -->
*    </code>
*    </pre>*
    <!-- the later is better but might be problematic for non-21"
monitors... -->
    <!--pre><xsl:value-of select="."/></pre-->
</xsl:template>

Re: Invalid use of string utils in

Posted by Michael Giroux <ml...@gmail.com>.
Antoine,
Sorry for the long delay in response.  I'm just back from 3 weeks of
vacation.

I have installed ANT 1.7 and retested with the new template.  The good news
is that the new br-replace template does successfully replace newline with
<br> tags.  There is an important difference between the results produced
with this approach, and the approach I posted in the initial message (using
<pre> ... </pre> tags to wrap the output.  The difference is that in HTML,
multiple spaces are suppressed by most browsers resulting in output that is
not indented as originally produced by Exception.printStackTrace().

For example, the results using the ANT 1.7 version of the template is one
very long line of exception trace with <br/> tags as below:
junit.framework.AssertionFailedError: 38 compile Errors in
SimpleClassesJUnitTest project.<br/> at junit.framework.Assert.fail(
Assert.java:47)<br/>

this results in display as below (note lack of indenting for 2nd and
subsequent lines):
junit.framework.AssertionFailedError: Build Errors expected:<0> but was:<38>
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.failNotEquals(Assert.java:282)
at junit.framework.Assert.assertEquals(Assert.java:64)

The expected output would have been (note indenting):
junit.framework.AssertionFailedError: Build Errors expected:<0> but was:<38>
  at junit.framework.Assert.fail(Assert.java:47)
  at junit.framework.Assert.failNotEquals(Assert.java:282)
  at junit.framework.Assert.assertEquals(Assert.java:64)

The desired output is achieved using the technique I posted in the initial
message and shown here for your convenience.  Note the addition of <pre> ...
</pre> tags, and the xsl:value-of select="." to include the exception data.
If you can view this message in HTML, the changes are color coded tho
highlight them.


<!-- Style for the error and failure in the tescase template -->
<xsl:template name="display-failures">
    <xsl:choose>
        <xsl:when test="not(@message)">N/A</xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="@message"/>
        </xsl:otherwise>
    </xsl:choose>
    <!-- display the stacktrace -->
*    <pre>  <!-- mg -->*
    <code>
        <br/>
     *   <xsl:value-of select="." />  <!-- mg -->*
*        <!--  mg *
*            remove the original call to br-replace template
        <xsl:call-template name="br-replace">
            <xsl:with-param name="word" select="."/>
        </xsl:call-template>
         -->
*    </code>
*    </pre>  <!-- mg -->*
    <!-- the later is better but might be problematic for non-21"
monitors... -->
    <!--pre><xsl:value-of select="."/></pre-->
</xsl:template>


The original code (below) does not use <pre> and calls br-replace to replace
NL w/ <br> tags.

    <!-- display the stacktrace -->
    <code>
        <br/><br/>
        <xsl:call-template name="br-replace">
            <xsl:with-param name="word" select="."/>
        </xsl:call-template>
    </code>
Do you still need this posted to bugzilla?

Michael

Re: Invalid use of string utils in

Posted by Antoine Levy-Lambert <an...@gmx.de>.
Hello Michael,

could you post your solution in Bugzilla, with the output of svn diff  
for junit-noframes.xsl ?

Regards,

Antoine
On Dec 8, 2006, at 12:41 PM, Michael Giroux wrote:

> Following is an excerpt from $ANT_HOME/etc/junit-noframes.xsl.
>
> <!--
>    template that will convert a carriage return into a br tag
>    @param word the text from which to convert CR to BR tag
> -->
> <xsl:template name="br-replace">
>    <xsl:param name="word"/>
>    <xsl:param name="br"><br/></xsl:param>
>    <xsl:value-of select='stringutils:replace(string($word),"&#xA;", 
> $br)'/>
> </xsl:template>
>
> The purpose of the template is to convert new-lines to <br/> tags  
> in text
> such as stack traces. This template does not insert the desired <br/ 
> > tags
> and only deletes the new-lines that are found.
>
> I chased this for a week in the XALAN mailing list to learn that  
> this is not
> valid.
>
> I was able to accomplish the desired effect (preserving formatting  
> of the
> stack trace) by adding <pre> ... </pre>  tags to the generated HTML  
> and
> removing the call to the br-replace template.  My solution is shown  
> below.
>
> Perhaps someone on the dev team could consider this for ANT 1.7?
>
> Michael Giroux
>
> <!-- Style for the error and failure in the tescase template -->
> <xsl:template name="display-failures">
>    <xsl:choose>
>        <xsl:when test="not(@message)">N/A</xsl:when>
>        <xsl:otherwise>
>            <xsl:value-of select="@message"/>
>        </xsl:otherwise>
>    </xsl:choose>
>    <!-- display the stacktrace -->
> *    <pre>*
>    <code>
>        <br/>
>        <xsl:value-of select="." />
> *        <!--
>        <xsl:call-template name="br-replace">
>            <xsl:with-param name="word" select="."/>
>        </xsl:call-template>
>         -->
> *    </code>
> *    </pre>*
>    <!-- the later is better but might be problematic for non-21"
> monitors... -->
>    <!--pre><xsl:value-of select="."/></pre-->
> </xsl:template>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org