Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to do the proper table header and table data alignment using xslt
    primarykey
    data
    text
    <p>Hi I have a xml and xslt code. Please any one help me to do the proper alignment with html table.I tried in the following method, but I did't get the proper result. Hereby I add the code.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" standalone="no"?&gt; &lt;?xml-stylesheet type="text/xsl" href="XSLTFile1.xslt"?&gt; &lt;culture-info current-culture="en-US" current-uiculture="en-US" /&gt; &lt;test-suite type="Test Project" name="" executed="True" result="Failure" success="False" time="0.290" asserts="0"&gt; &lt;results&gt; &lt;test-suite type="Assembly" name="D:\Samples\DemoNUnitTest\UnitTest\bin\Release\UnitTest.dll" executed="True" result="Failure" success="False" time="0.119" asserts="0"&gt; &lt;results&gt; &lt;test-suite type="Namespace" name="UnitTest" executed="True" result="Failure" success="False" time="0.101" asserts="0"&gt; &lt;results&gt; &lt;test-suite type="TestFixture" name="DemoUnitTest" executed="True" result="Success" success="True" time="0.075" asserts="0"&gt; &lt;results&gt; &lt;test-case name="UnitTest.DemoUnitTest.ShouldNotValidNumber" executed="True" result="Success" success="True" time="0.054" asserts="1" /&gt; &lt;test-case name="UnitTest.DemoUnitTest.ShouldValidNumber" executed="True" result="Success" success="True" time="0.000" asserts="1" /&gt; &lt;/results&gt; &lt;/test-suite&gt; &lt;test-suite type="TestFixture" name="NumberValidationTest" executed="True" result="Failure" success="False" time="0.019" asserts="0"&gt; &lt;results&gt; &lt;test-case name="UnitTest.NumberValidationTest.ShouldNotValidNumber" executed="True" result="Failure" success="False" time="0.014" asserts="1"&gt; &lt;failure&gt; &lt;message&gt; &lt;![CDATA[ Expected: True But was:False ]]&gt; &lt;/message&gt; &lt;stack-trace&gt; &lt;! CDATA[at UnitTest.NumberValidationTest.ShouldNotValidNumber() in D:\Samples\DemoNUnitTest \UnitTest\Class1.cs:line 24 ]]&gt; &lt;/stack-trace&gt; &lt;/failure&gt; &lt;/test-case&gt; &lt;test-case name="UnitTest.NumberValidationTest.ShouldValidNumber" executed="True" result="Success" success="True" time="0.001" asserts="1" /&gt; &lt;/results&gt; &lt;/test-suite&gt; &lt;/results&gt; &lt;/test-suite&gt; &lt;/results&gt; &lt;/test-suite&gt; &lt;test-suite type="Assembly" name="D:\Samples\UnitTest.dll" executed="True" result="Failure" success="False" time="0.106" asserts="0"&gt; &lt;results&gt; &lt;test-suite type="Namespace" name="UnitTest" executed="True" result="Failure" success="False" time="0.089" asserts="0"&gt; &lt;results&gt; &lt;test-suite type="TestFixture" name="DemoUnitTest" executed="True" result="Success" success="True" time="0.073" asserts="0"&gt; &lt;results&gt; &lt;test-case name="UnitTest.DemoUnitTest.ShouldNotValidNumber" executed="True" result="Success" success="True" time="0.058" asserts="1" /&gt; &lt;test-case name="UnitTest.DemoUnitTest.ShouldValidNumber" executed="True" result="Success" success="True" time="0.001" asserts="1" /&gt; &lt;/results&gt; &lt;/test-suite&gt; &lt;test-suite type="TestFixture" name="NumberValidationTest" executed="True" result="Failure" success="False" time="0.011" asserts="0"&gt; &lt;results&gt; &lt;test-case name="UnitTest.NumberValidationTest.ShouldNotValidNumber" executed="True" result="Failure" success="False" time="0.007" asserts="1"&gt; &lt;failure&gt; &lt;message&gt;&lt;![CDATA[ Expected: True But was: False]]&gt;&lt;/message&gt; &lt;stack-trace&gt; &lt;![CDATA[at UnitTest.NumberValidationTest.ShouldNotValidNumber() ]]&gt; &lt;/stack-trace&gt; &lt;/failure&gt; &lt;/test-case&gt; &lt;test-case name="UnitTest.NumberValidationTest.ShouldValidNumber" executed="True" result="Success" success="True" time="0.000" asserts="1" /&gt; &lt;/results&gt; &lt;/test-suite&gt; &lt;/results&gt; &lt;/test-suite&gt; &lt;/results&gt; &lt;/test-suite&gt; &lt;/results&gt; &lt;/test-suite&gt; &lt;/test-results&gt; </code></pre> <p>This is my XSL code</p> <pre><code> &lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="html"/&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;table border="1"&gt; &lt;!-- The tabel header --&gt; &lt;tr&gt; &lt;th&gt;Assembly&lt;/th&gt; &lt;/tr&gt; &lt;!-- selecting the assamblys --&gt; &lt;xsl:call-template name="cal"/&gt; &lt;/table&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;!-- template for the creation of tabel rows --&gt; &lt;xsl:template match="//test-suite[@type='Assembly']" name="cal" &gt; &lt;xsl:for-each select="//test-suite[@type='Assembly']"&gt; &lt;tr&gt; &lt;td&gt; &lt;xsl:value-of select="@name"/&gt; &lt;/td&gt; &lt;td colspan="0"&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;TestFixture&lt;/th&gt; &lt;/tr&gt; &lt;xsl:for-each select=".//test-suite[@type='TestFixture']"&gt; &lt;tr&gt; &lt;td colspan="0" &gt; &lt;xsl:value-of select="@name"/&gt; &lt;/td&gt; &lt;td &gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Test Cases&lt;/th&gt; &lt;th&gt;Result&lt;/th&gt; &lt;th&gt;Message&lt;/th&gt; &lt;/tr&gt; &lt;xsl:for-each select=".//test-case"&gt; &lt;tr&gt; &lt;td colspan="0"&gt; &lt;xsl:value-of select="@name"/&gt; &lt;/td&gt; &lt;xsl:choose &gt; &lt;xsl:when test="@result='Success'"&gt; &lt;td colspan="0"&gt; &lt;xsl:value-of select="@result"/&gt; &lt;/td&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise &gt; &lt;td bgcolor="red" &gt; &lt;xsl:value-of select="@result"/&gt; &lt;/td&gt; &lt;td bgcolor="red"&gt; &lt;xsl:value-of select=".//message"/&gt; &lt;/td&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>And My Result will look like the following: <img src="https://i.stack.imgur.com/3Lvv2.jpg" alt="Result Image"></p>
    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. 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