[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Following order & format specified in one document while displaying data from second document


Subject: [xsl] Following order & format specified in one document while displaying data from second document
From: Mulberry Technologies List Owner <owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 8 Jan 2004 18:33:50 -0500

From: "Sindigi, Ganesh K" <SindiGK@xxxxxxxxxxxxxxxxxxxxxx>
To: "'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Following order & format specified in one document while displayi
	ng data from second document
Date: Thu, 8 Jan 2004 12:08:22 -0700

Hello,

I have two xml documents, first one contains titles/headers
for the data in second file. Both are linked together with attribute 'id'
 of corresponding element/s.
The first file contains order in which data/fields needs to be displayed.
The
data file could contain data items in any order.  These are linked by
corresponding id's.  I have no control on the both of the input sources.
The size of data file could be in 10s of MB.

The data needs to be shown as HTML table format with headers
& orders from first file.
This table could contain nested tables which is determined by
attribute rowCount of element fieldGroup.

I need to come up with an XSL to achieve (in an efficient way) both
- have control on alignment of html-tables
- have control on order of data displayed

I am finding it difficult to align the titles columns with the data
displayed.
All the column headers are crumped up, not properly aligned with data
columns as
these two are formed from two different sources and html-tables inside a td
are
not able to align with subsequent data td's.
Also I am not able to display in the order specified by title/header
document.
Hope I am clear in explaining the problem.
Please suggest me how I could achieve this.

Thanks,
Ganesh.

PS: I had posted this two weeks back but could not get any help/hints, may
be
because experts on the list were on vacation.  Posting again with details
with
a hope to get help this time.

Here is XML titles document, source1:

<customerList id="regular" title="Regular Customers ">
<customer >
<field id="customerId" title="Customer Id"/>
<field id="customerName" title="Customer Name"/>
<fieldGroup rowcount="1" id="homeAddress" title="Home Address">
<fieldList>
<field id="street" title="Street"/>
<field id="city" title="City"/>
</fieldList>
</fieldGroup>
<fieldGroup rowCount="n" id="companyAddress" title="Company Address">
<fieldList>
<field id="street" title="Street"/>
<field id="city" title="City"/>
</fieldList>
</fieldGroup>
</customer>
</customerList>


Here is XML data document, source2:


<customerList id="regular" >
   <customer >
      <field id="customerName">Customer 1</field>
      <field id="customerId">cust1</field>
      <fieldGroup id="homeAddress">
         <data>
            <fieldList>
               <field id="street">98th Street </field>
               <field id="city">Chicago</field>
            </fieldList>
         </data>
      </fieldGroup>
      <fieldGroup id="companyAddress">
         <data>
            <fieldList>
               <field id="street">128th Street</field>
               <field id="city">Chicago</field>
            </fieldList>
            <fieldList>
               <field id="street">16th Street</field>
               <field id="city">NY</field>
            </fieldList>
         </data>
      </fieldGroup>
   </customer>
   <customer >
      <field id="customerName">Customer 2</field>
      <field id="customerId">cust2</field>
      <fieldGroup id="homeAddress">
         <data>
            <fieldList>
               <field id="street">-98th Street </field>
               <field id="city">Chicago</field>
            </fieldList>
         </data>
      </fieldGroup>
      <fieldGroup id="companyAddress">
         <data>
            <fieldList>
               <field id="street">South Hammerfield Parkway</field>
               <field id="city">Chicago</field>
            </fieldList>
            <fieldList>
               <field id="street">16th Street</field>
               <field id="city">NJ</field>
            </fieldList>
         </data>
      </fieldGroup>
   </customer>....
</customerList>
The headers File is passed in as parameter.

Here is stylesheet format.xsl:

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

   <xsl:key name="customerLookup" match="customerList/customer"
      use="ancestor-or-self::customerList/@id"/>

<xsl:param name="headersFile" select="''"/>

   <!-- Document containing headers/labels for the report  -->
   <xsl:variable name="headers" select="document($headersFile)"/>
   <xsl:variable name="fieldHeaders"
      select="document($headersFile)/customerList"/>

   <xsl:template match="/">
      <html>
         <body>
         <xsl:apply-templates/>
         </body>
      </html>
   </xsl:template>

  <xsl:template match="customerList">
      <h1 align="center">
         <xsl:for-each select="$fieldHeaders">
            <xsl:value-of select="@title"/>
         </xsl:for-each>
      </h1>
      <table border="1" align="center">
         <tr>
            <xsl:call-template name="pTH">
               <xsl:with-param name="cT" select="."/>
            </xsl:call-template>
         </tr>
      <xsl:apply-templates />
      </table>
      <p></p>
   </xsl:template>

   <xsl:template match="customer">
      <tr>
      <xsl:apply-templates />
      </tr>
   </xsl:template>


<xsl:template name="pTH"> <xsl:param name="cT"/> <xsl:for-each select="$fieldHeaders"> <xsl:for-each select="key('customerLookup', $cT/ancestor-or-self::customerList/@id)/*"> <xsl:variable name="switch" select="name(.)"/> <xsl:choose> <xsl:when test=" $switch = 'fieldGroup' "> <td> <xsl:call-template name="fTH"> <xsl:with-param name="ncT" select="."/> </xsl:call-template> </td> </xsl:when> <xsl:when test=" $switch = 'field' "> <td bgcolor="FFAACC" style="font-family:verdana;font-size:100%;color:black"> <xsl:value-of select="@title"/> </td> </xsl:when> </xsl:choose> </xsl:for-each> </xsl:for-each>

</xsl:template>

   <xsl:template name="fTH">
      <xsl:param name="ncT"/>
      <xsl:variable name="noOfCols" select="count($ncT/fieldList/field)"/>
      <table border="1" width="100%" height="100%">
      <tr>
         <td colspan="{$noOfCols}" bgcolor="88FF88"
            style="font-family:verdana;font-size:100%;color:black">
            <xsl:value-of select="$ncT/@title"/>
         </td>
      </tr>
      <tr>
         <xsl:for-each select="$ncT/fieldList/field">
               <td bgcolor="FFAACC"
                  style="font-family:verdana;font-size:100%;color:black">
                  <xsl:value-of select="@title"/>
               </td>
         </xsl:for-each>
      </tr>
      </table>
   </xsl:template>

   <xsl:template match="fieldGroup">
      <td><table border="1" width="100%" height="100%">
         <xsl:apply-templates />
      </table></td>
   </xsl:template>
   <xsl:template match="fieldList">

      <tr>
           <xsl:apply-templates />
      </tr>

</xsl:template>

   <xsl:template match="field">
      <td>
         <xsl:value-of select="text()"/>
      </td>
   </xsl:template>

   <xsl:template match="text()"/>
</xsl:stylesheet>

Desired Output html :

----------------------------------------------------------------------------
-
Customer Id	Customer Name	  Home Address	   Company Address
				  Street      City	  Street       City
----------------------------------------------------------------------------
-
cust1		Customer 1	  98thStreet Chicago	128th Street
Chicago

---------------------
				                        16th Street   NY
----------------------------------------------------------------------------
-
cust2		Customer 2	  98thStreet Chicago	128th Street
Chicago

---------------------
				                        16th Street   NY

---------------------
				                        16th Street   NJ

Note: This is not similar to data posted in souce2.xml, for clarity I have
put
some dummy data.


--
======================================================================
B. Tommie Usdin mailto:btusdin@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Phone: 301/315-9631
Suite 207 Direct Line: 301/315-9634
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in XML and SGML
======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords