Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Here is a complete transformation</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="/*"&gt; &lt;style type="text/css"&gt; .FAIL {color:red;} &lt;/style&gt; &lt;h1&gt;Results from tests:&lt;/h1&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="parameters"&gt; &lt;h2&gt; &lt;xsl:number count="parameters" /&gt; User &lt;xsl:value-of select="user_id"/&gt; &lt;/h2&gt; &lt;h3&gt; &lt;xsl:value-of select="test_name"/&gt; (&lt;xsl:value-of select="test_id"/&gt;) &lt;/h3&gt; &lt;dl&gt; &lt;dt&gt;Transcript&lt;/dt&gt; &lt;dd&gt;&lt;xsl:value-of select="transcript"/&gt;&lt;/dd&gt; &lt;dt&gt;Percentage&lt;/dt&gt; &lt;dd&gt; &lt;xsl:value-of select="percentage"/&gt; &lt;/dd&gt; &lt;dt&gt;Result&lt;/dt&gt; &lt;dd&gt; &lt;xsl:if test="test_result = 'FAIL'"&gt; &lt;xsl:attribute name="class"&gt;FAIL&lt;/xsl:attribute&gt; &lt;/xsl:if&gt; (&lt;xsl:value-of select="test_result"/&gt;) &lt;/dd&gt; &lt;dt&gt;Date/Time of test&lt;/dt&gt; &lt;dd&gt;&lt;xsl:value-of select="time"/&gt;&lt;/dd&gt; &lt;/dl&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>When this transformation is applied on the provided XML document:</strong></p> <pre><code>&lt;request xmlns:xsi="httyp://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="results.xsd"&gt; &lt;authentication password="turkey" partnerid="exam" /&gt; &lt;method name="ListUserTestResults"&gt; &lt;parameters&gt; &lt;user_id&gt;42511&lt;/user_id&gt; &lt;transcript&gt;4234232&lt;/transcript&gt; &lt;test_id&gt;231&lt;/test_id&gt; &lt;test_name&gt;ASP 3.0 Test&lt;/test_name&gt; &lt;percentage&gt;75&lt;/percentage&gt; &lt;test_result&gt;PASS&lt;/test_result&gt; &lt;time&gt;2006-04-19T14:05:11Z&lt;/time&gt; &lt;/parameters&gt; &lt;parameters&gt; &lt;user_id&gt;42511&lt;/user_id&gt; &lt;transcript&gt;2356545&lt;/transcript&gt; &lt;test_id&gt;12&lt;/test_id&gt; &lt;test_name&gt;PHP 5.0 Test&lt;/test_name&gt; &lt;percentage&gt;35&lt;/percentage&gt; &lt;test_result&gt;FAIL&lt;/test_result&gt; &lt;time&gt;2006-05-17T10:19:45Z&lt;/time&gt; &lt;/parameters&gt; &lt;/method&gt; &lt;/request&gt; </code></pre> <p><strong>the wanted, correct result is produced:</strong></p> <pre><code>&lt;style type="text/css"&gt; .FAIL {color:red;} &lt;/style&gt; &lt;h1&gt;Results from tests:&lt;/h1&gt; &lt;h2&gt;1 User 42511&lt;/h2&gt; &lt;h3&gt;ASP 3.0 Test (231) &lt;/h3&gt; &lt;dl&gt; &lt;dt&gt;Transcript&lt;/dt&gt; &lt;dd&gt;4234232&lt;/dd&gt; &lt;dt&gt;Percentage&lt;/dt&gt; &lt;dd&gt;75&lt;/dd&gt; &lt;dt&gt;Result&lt;/dt&gt; &lt;dd&gt; (PASS) &lt;/dd&gt; &lt;dt&gt;Date/Time of test&lt;/dt&gt; &lt;dd&gt;2006-04-19T14:05:11Z&lt;/dd&gt; &lt;/dl&gt; &lt;h2&gt;2 User 42511&lt;/h2&gt; &lt;h3&gt;PHP 5.0 Test (12) &lt;/h3&gt; &lt;dl&gt; &lt;dt&gt;Transcript&lt;/dt&gt; &lt;dd&gt;2356545&lt;/dd&gt; &lt;dt&gt;Percentage&lt;/dt&gt; &lt;dd&gt;35&lt;/dd&gt; &lt;dt&gt;Result&lt;/dt&gt; &lt;dd class="FAIL"&gt; (FAIL) &lt;/dd&gt; &lt;dt&gt;Date/Time of test&lt;/dt&gt; &lt;dd&gt;2006-05-17T10:19:45Z&lt;/dd&gt; &lt;/dl&gt; </code></pre> <p><strong>Explanation</strong>:</p> <p>Proper use of <strong><a href="http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl%3aif" rel="nofollow"><code>xsl:if</code></a></strong> and <strong><a href="http://www.w3.org/TR/xslt#creating-attributes" rel="nofollow"><code>xsl:attribute</code></a></strong>.</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.
    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