Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add times in XSLT?
    primarykey
    data
    text
    <p>I have some output from 3rd party software:</p> <p>Sample XML from the software:</p> <pre><code>&lt;testsuite name="XYZ"&gt; &lt;testcase name="ABC" status="0" time="12.001"&gt;Some stuff&lt;/testcase&gt; &lt;testcase name="DEF" status="0" time="12,345.001"&gt;Some stuff&lt;/testcase&gt; &lt;testcase name="GHI" status="0" time="4,321.001"&gt;Some stuff&lt;/testcase&gt; &lt;/testsuite&gt; </code></pre> <p>I need to write an XSLT that transforms this into the following:</p> <pre><code>&lt;testsuite name="XYZ" time="16678.003"&gt; &lt;testcase name="ABC" time="12.001"&gt;Some stuff&lt;/testcase&gt; &lt;testcase name="DEF" time="12,345.001"&gt;Some stuff&lt;/testcase&gt; &lt;testcase name="GHI" time="4,321.001"&gt;Some stuff&lt;/testcase&gt; &lt;/testsuite&gt; </code></pre> <p>And I have almost got there, with the exception of the <strong>time</strong> attribute of the <strong>testsuite</strong> element. Instead of getting the total, I am getting <strong>NaN</strong>. The XPath expression I am using to get this is <strong>sum(//testsuite/@time)</strong></p> <p>Note that the error does not occur when there all the times are &lt; 1000. This is probably because XSLT doesn't parse the number when it encounters commas. (I cannot get rid of these commas from the input because it comes from 3rd party software.)</p> <p>So how do I sum these values for time? Is there away to modify <strong>sum(//testsuite/@time)</strong> such that it is able to strip commas on the fly?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload