0

I am trying to parse a xml to generate a html report.The problematic section of the xml is as given

<failure message="Management changes link count is not 3$HiHello" type="junit.framework.AssertionFailedError">junit.framework.AssertionFailedError: Management changes link count is not 3$HiHelloJI
at CustomProjects.CommonTemplates.verifyManagementChanges(Unknown Source)
at CustomProjects.EmersonTest.testEmerson_VerifyManagementChanges(Unknown Source)
</failure>

The xslt written for parsing this is :

<xsl:choose>
        <xsl:when test="failure">
            <td>Failure</td>
            <td><xsl:apply-templates select="failure"/></td>
            <td><a href="ftp://10.32.1.66/seleniumScreenshotsFireFoxTest/{@name}.png" target="_blank">screenshot</a></td>
            <td><xsl:apply-templates select="failurelink"/></td>
        </xsl:when>
</xsl:choose>

<xsl:template match="failure">
  <xsl:call-template name="display-failures"/>
</xsl:template>

<xsl:template match="failurelink">
  <xsl:call-template name="display-failures-link"/>
</xsl:template>

<xsl:template name="display-failures">
  <xsl:param name="FailText" select="@message"/>
    <xsl:choose>
     <xsl:when test="not(@message)">N/A</xsl:when>
    <xsl:otherwise>
       <xsl:value-of select="substring-before($FailText,'$')"/>
    </xsl:otherwise>
</xsl:choose>
<!-- display the stacktrace -->
<code>
    <br/><br/>
    <xsl:call-template name="br-replace">
        <xsl:with-param name="word" select="."/>
    </xsl:call-template>
</code>
<!-- the later is better but might be problematic for non-21" monitors... -->
<!--pre><xsl:value-of select="."/></pre-->
</xsl:template>

<xsl:template name="display-failures-link">
<xsl:param name="linktext" select="@message"/>
 <xsl:choose>
    <xsl:when test="not(@message)">N/A</xsl:when>
    <xsl:otherwise>
       <xsl:value-of select="substring-after($linktext,'$')"/>
    </xsl:otherwise>
</xsl:choose>
<!-- display the stacktrace -->
<code>
    <br/><br/>
    <xsl:call-template name="br-replace">
        <xsl:with-param name="word" select="."/>
    </xsl:call-template>
</code>
<!-- the later is better but might be problematic for non-21" monitors... -->
<!--pre><xsl:value-of select="."/></pre-->
</xsl:template>

Here I am getting the desired result(The String before $ sign) from display-failures template but on calling display-failures-link I am getting nothing.(Should get the string after $ sign).I dont know whether the problem is with sunstring function or with something else.Kindly let me know what I am doing wrong here.

Any help is highly appreciated.

1
  • 1
    Glad to help, but you could please indent your XSL properly? Also, why do you have an <xsl:choose> element at the top level? Why are you calling templates that take parameters but not giving them parameters? More generally, why do you have match-based templates calling other templates like this? It would be much easier to figure out what might be going on with the substring matching without having to plow through that extra layer of muck. Also, please give the question a name stating what it's about. Commented Feb 5, 2013 at 9:02

1 Answer 1

3

The problem here is that you are trying to apply-templates on the XPath failurelink, but you don't have an element called <failurelink>, so this apply-templates isn't finding anything.

<xsl:apply-templates select="failurelink"/>

One way to apply two different templates on the same kind of element is to use modes:

<xsl:template match="failure">
  <xsl:call-template name="display-failures"/>
</xsl:template>

<xsl:template match="failure" mode="link">
  <xsl:call-template name="display-failures-link"/>
</xsl:template>

Then the area where you apply the templates would change to this:

<td>Failure</td>
<td><xsl:apply-templates select="failure"/></td>
<td><a href="ftp://10.32.1.66/seleniumScreenshotsFireFoxTest/{@name}.png" target="_blank">screenshot</a></td>
<td><xsl:apply-templates select="failure" mode="link"/></td>

But in your case, there's an even better approach. Just eliminate the second template, and do this:

Replace the whole <xsl:choose> with:

<xsl:apply-templates select="failure" />

Replace the first template you listed with:

<xsl:template match="failure">
   <td>Failure</td>
   <td><xsl:call-template name="display-failures"/></td>
   <td><a href="ftp://10.32.1.66/seleniumScreenshotsFireFoxTest/{../@name}.png" target="_blank">screenshot</a></td>
   <td><xsl:call-template name="display-failures-link"/></td>
</xsl:template>

And delete the second template you listed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.