Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT & XML Help - Not generating html with two different XML elements
    text
    copied!<p>I have a problem with combining my XSLT and XML in a certain situation and I am stuck, below is an example of my issue:</p> <p>XML:</p> <pre><code>&lt;a&gt; &lt;x&gt; &lt;y testname="test1"&gt; &lt;object elementname="Name" elementvalue="true" elementvalue1="ABC" elementvalue2="ADF"&gt; &lt;comparisonresult&gt;false&lt;/comparisonresult&gt; &lt;/object&gt; &lt;/y&gt; &lt;/x&gt; &lt;/a&gt; </code></pre> <p>XSLT:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;body&gt; &lt;font face="Arial"&gt; &lt;h2&gt;HEADINGY&lt;/h2&gt; &lt;h4&gt;Process 1&lt;/h4&gt; &lt;h4&gt;More Process&lt;/h4&gt; &lt;h4&gt;Additional &lt;/h4&gt; &lt;table border="1"&gt; &lt;tr bgcolor="#dccdc"&gt; &lt;th align="center"&gt;T1&lt;/th&gt; &lt;th align="center"&gt;T2&lt;/th&gt; &lt;th align="center"&gt;T3&lt;/th&gt; &lt;/tr&gt; &lt;/table&gt; &lt;h2&gt;Main&lt;/h2&gt; &lt;xsl:for-each select="a/x/y"&gt; &lt;h3&gt; &lt;xsl:value-of select="@testname" /&gt; &lt;/h3&gt; &lt;h4&gt;Heading 1&lt;/h4&gt; &lt;table border="1" style="display:inline"&gt; &lt;tr bgcolor="#CECEF6"&gt; &lt;th align="center"&gt;Item1&lt;/th&gt; &lt;th align="center"&gt;Item2&lt;/th&gt; &lt;th align="center"&gt;Item3&lt;/th&gt; &lt;/tr&gt; &lt;xsl:for-each select="object"&gt; &lt;tr&gt; &lt;td bgcolor="#F2F5A9"&gt; &lt;xsl:value-of select="@elementname" /&gt; &lt;/td&gt; &lt;td bgcolor="#F2F5A9"&gt; &lt;xsl:value-of select="@elementvalue1" /&gt; &lt;/td&gt; &lt;td bgcolor="#F2F5A9"&gt; &lt;xsl:value-of select="@elementvalue2" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;/xsl:for-each&gt; &lt;/font&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>If you enter these two into <a href="http://www.w3schools.com/xml/tryxslt.asp?xmlfile=simple&amp;xsltfile=simple" rel="nofollow">http://www.w3schools.com/xml/tryxslt.asp?xmlfile=simple&amp;xsltfile=simple</a> you get output as expected. The issue comes when i added the following to the XML, so it looks like:</p> <pre><code>&lt;a&gt; &lt;x&gt; &lt;y testname="test1"&gt; &lt;object elementname="Name" elementvalue="true" elementvalue1="ABC" elementvalue2="ADF"&gt; &lt;comparisonresult&gt;false&lt;/comparisonresult&gt; &lt;/comparisonobject&gt; &lt;/y&gt; &lt;x&gt; &lt;t testname="ComparisonResult"&gt; &lt;step stepname="Add x" stepresult="Add x"&gt; &lt;result&gt;true&lt;/result&gt; &lt;/step&gt; &lt;/t&gt; &lt;/a&gt; </code></pre> <p>and the corresponding xslt:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;body&gt; &lt;font face="Arial"&gt; &lt;h2&gt;HEADINGY&lt;/h2&gt; &lt;h4&gt;Process 1&lt;/h4&gt; &lt;h4&gt;More Process&lt;/h4&gt; &lt;xsl:for-each select="a/x/t"&gt; &lt;xsl:for-each select="testname"&gt; &lt;h4&gt;Additional &lt;/h4&gt; &lt;table border="1"&gt; &lt;tr bgcolor="#dccdc"&gt; &lt;th align="center"&gt;T1&lt;/th&gt; &lt;th align="center"&gt;T2&lt;/th&gt; &lt;th align="center"&gt;T3&lt;/th&gt; &lt;/tr&gt; &lt;xsl:for-each select="stepname"&gt; &lt;tr&gt; &lt;td bgcolor="#F2F5A9"&gt; &lt;xsl:value-of select="@stepname" /&gt; &lt;/td&gt; &lt;td bgcolor="#F2F5A9"&gt; &lt;xsl:value-of select="@step result" /&gt; &lt;/td&gt; &lt;td bgcolor="#F2F5A9"&gt; &lt;xsl:value-of select="@result" /&gt; &lt;/td&gt; &lt;/table&gt; &lt;h2&gt;Main&lt;/h2&gt; &lt;xsl:for-each select="a/x/y"&gt; &lt;h3&gt; &lt;xsl:value-of select="@testname" /&gt; &lt;/h3&gt; &lt;h4&gt;Heading 1&lt;/h4&gt; &lt;table border="1" style="display:inline"&gt; &lt;tr bgcolor="#CECEF6"&gt; &lt;th align="center"&gt;Item1&lt;/th&gt; &lt;th align="center"&gt;Item2&lt;/th&gt; &lt;th align="center"&gt;Item3&lt;/th&gt; &lt;/tr&gt; &lt;xsl:for-each select="object"&gt; &lt;tr&gt; &lt;td bgcolor="#F2F5A9"&gt; &lt;xsl:value-of select="@elementname" /&gt; &lt;/td&gt; &lt;td bgcolor="#F2F5A9"&gt; &lt;xsl:value-of select="@elementvalue1" /&gt; &lt;/td&gt; &lt;td bgcolor="#F2F5A9"&gt; &lt;xsl:value-of select="@elementvalue2" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;/xsl:for-each&gt; &lt;/font&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>I just get a blank page. I know there is a lot here to digest, but im really stuck!</p> <p>Thanks</p>
 

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