Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 17th, 2013, 02:38 PM
Registered User
 
Join Date: Aug 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Generating HTML Report from xml input file using stylesheet

I am having the below input XML file:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ConfigurationSetDataExtract>

  <SOSData>
    <OptionData>
      <Option Name="KeyBoard" Value="Black"/>
      <Option Name="Monitor" Value="15"/>
      <Option Name="RAM" Value="8 GB"/>
    </OptionData>
    <VariantItem ItemID="000028"/>
  </SOSData>

  <SOSData>
    <OptionData>
      <Option Name="Controller Type" Value="Controller Type 1"/>
      <Option Name="Spindle Type" Value="Single"/>
      <Option Name="With Tailstock" Value="True"/>
    </OptionData>
    <VariantItem ItemID="000039"/>
  </SOSData>

  <SOSData>
    <OptionData>
      <Option Name="Controller Type" Value="Controller Type 1"/>
      <Option Name="Spindle Type" Value="Single"/>
      <Option Name="With Tailstock" Value="True"/>
    </OptionData>
    <VariantItem ItemID="000040"/>
  </SOSData>

  <SOSData>
    <OptionData>
      <Option Name="Controller Type" Value="Controller Type 1"/>
      <Option Name="Spindle Type" Value="Single"/>
      <Option Name="With Tailstock" Value="True"/>
    </OptionData>
    <VariantItem ItemID="000041"/>
  </SOSData>

  <SOSData>
    <OptionData>
      <Option Name="KeyBoard" Value="Black"/>
      <Option Name="Monitor" Value="15"/>
      <Option Name="RAM" Value="8 GB"/>
    </OptionData>
    <VariantItem ItemID="000029"/>
  </SOSData>

</ConfigurationSetDataExtract>
Using xsl stylesheet (xslt version 1.0) I need to generate HTML Report file having the below format:
Code:
            Sos Data                                  Variant Items
    Name                Value

Controller Type     Controller Type 1              000039
Spindle Type         Single                            000040 
With Tailstock      True                               000041


    Name                Value

 KeyBoard              Black                             000028
 Monitor                 15                                000029
 RAM                     8 GB
Please note as shown in the input xml file the same element in may not be in order.

I have tried writing sample stylesheet, but it is this Grouping based on <OptionData> and < VariantItem> where I am stuck.

Here is my sample stylesheet:

Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
<xsl:output method="html" indent="yes"/>

<xsl:key name="ItemRevision" match="ItemRevision" use="@object_string_selected"/>

<xsl:template match="/">
<head>
	<title>Configuration Set Report</title>
	<script type="text/javascript">
	<!--	function expcol(divId)
		{
		    var div = document.getElementsByName(divId);
			
			alert('welcome' + divId);
			if (div.style.display=='none')
			{
				div.style.display = 'block';
			}
			else
			{
				div.style.display = 'none';
			}
			return true; 
		} -->
		
		function toggleSibling()
		{
			if (window.event.srcElement.nextSibling.style.display=="none")
				window.event.srcElement.nextSibling.style.display = "block";
			else
				window.event.srcElement.nextSibling.style.display = "none";
		}
	
	</script >

	 <style>
			table
				{
					border-collapse: collapse;
					border-spacing: 0pt;
					width: 100%;
					empty-cells: show;
					border-color:#000000;
				}
			td
				{
					border-style:solid;
					border-width:0.2pt;
					border-color:#000000;
					font-family: Arial, Helvetica, sans-serif;
				}
			th
				{
					border-style:solid;
					border-width:0.2pt;
					border-color:#000000;
					background-color: #CCCCFF;
					font-family: Arial, Helvetica, sans-serif;
				}
							<!-- Support for Foxfire browser requires specific class="sample" on all table elements -->
							table.sample  th
							{
									border-style:solid;
									border-width: 1px 1px 1px 1px;
									border-color: black black black black;
									padding: 1px 1px 1px 1px;
									background-color: #CCCCFF;
									font-family: Arial, Helvetica, sans-serif;
							}
							table.sample  tr
							{
									border-style:solid;
									border-width: 1px 1px 1px 1px;
									border-color: black black black black;
									background-color: white;
									font-family: Arial, Helvetica, sans-serif;
							}
							table.sample td
							{
									border-style: solid;
									border-width: 1px 1px 1px 1px;
									border-color: black black black black;
									padding: 1px 1px 1px 1px;
									background-color: white;
									font-family: Arial, Helvetica, sans-serif;
							}
			.headings
			{
				background-color: #CCCCFF;
				font-family: Arial, Helvetica, sans-serif;
			}
		</style>
	</head>
<body BGCOLOR="#FFFFFF" link="#0000FF" vlink="#660066">
	<br/>
	<table class="sample">
		<tr><!-- main table:row1::heading-->
			<th>
				<div align="left">
                     <img alt="Sample" src="C:\\Sample.jpg">
						</img>
				</div>
				<div align="center">
					<font size="+2">
						Configuration Set Report
					</font>
				</div>
			</th>
		</tr>
		<tr> <!-- Table for variant Items -->
			<td>
				 <hr color="#000000"/>
				 <table> <!-- Selected Object Details -->
					<tr align="center"> 
						<th>SOS Data</th>
						<th>Variant Items </th>
					</tr>
					<xsl:for-each select="ConfigurationSetDataExtract/SOSData">
						<tr align="center">
							<td>
								<p>
								   <table>
									 <tr>
										<th>Name</th>
										<th>Value</th>	

                                    <xsl:for-each select="OptionData/Option">
        
                                       <tr>
										   <td width="150px" align="center"><xsl:value-of select="@Name"/></td>
										   <td width="150px" align="center"><xsl:value-of select="@Value"/></td>
									   </tr>

                                    </xsl:for-each>
										
									</tr>
                                    </table>									
								</p>
							</td>
							<td>									
                                     <xsl:for-each select="VariantItem">
									       <p>
										   <xsl:value-of select="@ItemID"/>
										   </p>										 								
                                    </xsl:for-each>
								
									  </td>
									  
						</tr>										
					</xsl:for-each>
				</table>
			</td>
		</tr>
	</table>

	</body>
	</xsl:template>
</xsl:stylesheet>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple input xml / get data from other xml file elayaraja.s XSLT 3 July 25th, 2008 06:59 AM
How to ignore namespaces in input xml file hanifa XSLT 2 February 14th, 2007 04:14 AM
Input data from file to report in .net krisXp Crystal Reports 0 May 4th, 2006 07:13 AM
Retrive text from input type field of html file?? bikash Javascript 10 July 30th, 2003 04:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.