Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your rules are slightly confusing, but I believe I have a solution for you.</p> <p><strong>When this XSLT:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt; &lt;xsl:output omit-xml-declaration="no" indent="yes" /&gt; &lt;xsl:strip-space elements="*" /&gt; &lt;xsl:template match="/*"&gt; &lt;testsuites&gt; &lt;testsuite&gt; &lt;xsl:apply-templates select="/*/*/*/dict[integer = '4']" /&gt; &lt;/testsuite&gt; &lt;/testsuites&gt; &lt;/xsl:template&gt; &lt;xsl:template match="dict[string[1] = 'Fail']"&gt; &lt;testcase classname="{string[2]}" name="{string[2]}"&gt; &lt;failure&gt; &lt;xsl:value-of select="string[2]" /&gt; &lt;xsl:if test="following-sibling::dict[1]/string[1] = 'Error'"&gt; &lt;xsl:value-of select="concat( ' - ', following-sibling::dict[string[1] = 'Error'][1]/string[2])" /&gt; &lt;/xsl:if&gt; &lt;/failure&gt; &lt;/testcase&gt; &lt;/xsl:template&gt; &lt;xsl:template match="dict[not(string[1] = 'Fail')]"&gt; &lt;testcase classname="{string[2]}" name="{string[2]}" /&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>..is applied to the provided XML:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;plist&gt; &lt;dict&gt; &lt;array&gt; &lt;dict&gt; &lt;key&gt;LogType&lt;/key&gt; &lt;string&gt;Pass&lt;/string&gt; &lt;key&gt;Message&lt;/key&gt; &lt;string&gt;Test 1&lt;/string&gt; &lt;key&gt;Timestamp&lt;/key&gt; &lt;date&gt;2012-10-26T09:42:41Z&lt;/date&gt; &lt;key&gt;Type&lt;/key&gt; &lt;integer&gt;4&lt;/integer&gt; &lt;/dict&gt; &lt;dict&gt; &lt;key&gt;LogType&lt;/key&gt; &lt;string&gt;Pass&lt;/string&gt; &lt;key&gt;Message&lt;/key&gt; &lt;string&gt;Test 1&lt;/string&gt; &lt;key&gt;Timestamp&lt;/key&gt; &lt;date&gt;2012-10-26T09:43:27Z&lt;/date&gt; &lt;key&gt;Type&lt;/key&gt; &lt;integer&gt;5&lt;/integer&gt; &lt;/dict&gt; &lt;dict&gt; &lt;key&gt;LogType&lt;/key&gt; &lt;string&gt;Fail&lt;/string&gt; &lt;key&gt;Message&lt;/key&gt; &lt;string&gt;Inserting content to a group&lt;/string&gt; &lt;key&gt;Timestamp&lt;/key&gt; &lt;date&gt;2012-10-26T09:49:13Z&lt;/date&gt; &lt;key&gt;Type&lt;/key&gt; &lt;integer&gt;4&lt;/integer&gt; &lt;/dict&gt; &lt;dict&gt; &lt;key&gt;LogType&lt;/key&gt; &lt;string&gt;Error&lt;/string&gt; &lt;key&gt;Message&lt;/key&gt; &lt;string&gt;VerboseError: target.frontMostApp().mainWindow().buttons()[3] could not be tapped&lt;/string&gt; &lt;key&gt;Screenshot&lt;/key&gt; &lt;string /&gt; &lt;key&gt;Timestamp&lt;/key&gt; &lt;date&gt;2012-10-26T09:50:12Z&lt;/date&gt; &lt;key&gt;Type&lt;/key&gt; &lt;integer&gt;3&lt;/integer&gt; &lt;/dict&gt; &lt;dict&gt; &lt;key&gt;LogType&lt;/key&gt; &lt;string&gt;Fail&lt;/string&gt; &lt;key&gt;Message&lt;/key&gt; &lt;string&gt;Inserting content to a group&lt;/string&gt; &lt;key&gt;Screenshot&lt;/key&gt; &lt;string /&gt; &lt;key&gt;Timestamp&lt;/key&gt; &lt;date&gt;2012-10-26T09:50:13Z&lt;/date&gt; &lt;key&gt;Type&lt;/key&gt; &lt;integer&gt;7&lt;/integer&gt; &lt;/dict&gt; &lt;/array&gt; &lt;/dict&gt; &lt;/plist&gt; </code></pre> <p><strong>...the expected result is produced:</strong></p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;testsuites&gt; &lt;testsuite&gt; &lt;testcase classname="Test 1" name="Test 1" /&gt; &lt;testcase classname="Inserting content to a group" name="Inserting content to a group"&gt; &lt;failure&gt;Inserting content to a group - VerboseError: target.frontMostApp().mainWindow().buttons()[3] could not be tapped&lt;/failure&gt; &lt;/testcase&gt; &lt;/testsuite&gt; &lt;/testsuites&gt; </code></pre> <p><strong>Explanation:</strong></p> <ul> <li>The first template creates new <code>&lt;testsuites&gt;</code> and <code>&lt;testsuite&gt;</code> elements. The XSLT processor is then instructed to process all <code>&lt;dict&gt;</code> descendants whose <code>&lt;integer&gt;</code> child has a value of 4.</li> <li>The second template matches all <code>&lt;dict&gt;</code> elements whose first <code>&lt;string&gt;</code> child has a value of "Fail". In this case, a new <code>&lt;testcase&gt;</code> and <code>&lt;failure&gt;</code> element pair is created and given a value that conforms to the rules you have provided.</li> <li>The final template matches all <code>&lt;dict&gt;</code> elements whose first <code>&lt;string&gt;</code> child has a value of anything other than "Fail". In this case, a new <code>&lt;testcase&gt;</code> element is created and given values per your rules.</li> </ul>
 

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