Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This transformation produces the subheading and name for each testcase</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="testcase"&gt; Subheading: &lt;xsl:value-of select= "substring-before(substring-after(@name, 'test'), '_' ) "/&gt; Name: &lt;xsl:value-of select="substring-after(@name, '_')"/&gt; &lt;xsl:text&gt;&amp;#xA;&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>When applied on the provided XML document:</strong></p> <pre><code>&lt;testsuites&gt; &lt;testsuite name="testPacketProcessor" tests="27" failures="0" disabled="0" errors="0" time="36.875"&gt; &lt;testcase name="testInitialise_IpNotSet" status="run" time="0" classname="testPacketProcessor" /&gt; &lt;testcase name="testInitialise_GoodIp" status="run" time="2.046" classname="testPacketProcessor" /&gt; &lt;testcase name="testInitialise_BadIp" status="run" time="0.032" classname="testPacketProcessor" /&gt; &lt;/testsuite&gt; &lt;/testsuites&gt; </code></pre> <p><strong>the wanted, correct result is produced</strong>:</p> <pre><code> Subheading: Initialise Name: IpNotSet Subheading: Initialise Name: GoodIp Subheading: Initialise Name: BadIp </code></pre> <p><strong>Explanation</strong>: Using the standard XPath functions <code>substring-before()</code> and <code>substring-after()</code></p> <p><strong>Edit</strong>: In a comment the OP clarified that he wanted grouping by function (tired of bad questions ?):</p> <p><strong>This transformation performs the wanted grouping:</strong></p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:key name="kTestsByFunction" match="testcase" use="substring-before(substring-after(@name, 'test'), '_' )" /&gt; &lt;xsl:template match= "testcase [generate-id() = generate-id(key('kTestsByFunction', substring-before(substring-after(@name, 'test'), '_' ) )[1] ) ] "&gt; Subheading: &lt;xsl:value-of select= "substring-before(substring-after(@name, 'test'), '_' ) "/&gt; &lt;xsl:for-each select= "key('kTestsByFunction', substring-before(substring-after(@name, 'test'), '_' ) ) "&gt; Name: &lt;xsl:value-of select="substring-after(@name, '_')"/&gt; &lt;xsl:text&gt;&amp;#xA;&lt;/xsl:text&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>and produces the wanted result</strong>:</p> <pre><code> Subheading: Initialise Name: IpNotSet Name: GoodIp Name: BadIp </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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