Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 12th, 2004, 05:22 PM
Registered User
 
Join Date: Jun 2004
Location: Raheen, Limerick, Ireland.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple XML files matched with common Number Id

Hi,


I'm new to XSLT and I'm strugling trying to get this done. I'd really appreciate any help.

I have multiple sources of XML. There is one file which contains the test definitions (test number, its name, and its unit). The other files contain experiments, etc. per each of these tests. I'm trying to develop an XSLT that transforms this into an HTML table (see below for a simplified example).


XML File 1: definitions.xml

<tests>
- <test number="1">
     <Name>Test 1</Name>
     <Unit>Celsius</Unit>
  </test>
- <test number="2">
  <Name>Test 2</Name>
  <Unit />
  </test>
- <test number="4">
  <Name>Test Blah</Name>
  <Unit>Km</Unit>
  </test>
...
<tests>

----------

XML File 2: experiments.xml
<experiment>
- <temperature value="25degC">
     <test number="1">
        <Sigma>0.23</Sigma>
        <Mean>10.44</Mean>
     </test>
     <test number="3">
        <Sigma>0.13</Sigma>
        <Mean>11.33</Mean>
     </test>
- <temperature value="50degC">
     <test number="1">
        <Sigma>1.22</Sigma>
        <Mean>13.13</Mean>
     </test>
     <test number="2">
        <Sigma>0.16</Sigma>
        <Mean>0.31</Mean>
     </test>
  ....


=======
OUTPUT should be something like this, where tests numbers will be mathched. If it is missing in any side, it'll still be output, but either with the test name/unit missing, or with the experiment data missing>

<table border=1 cellpadding=0>
<thead>
 <tr>
  <td rowspan=2>Test No</td>
  <td rowspan=2>Name</td>
  <td rowspan=2>Unit</td>
  <td colspan=2>25degC</td>
  <td colspan=2>50degC</td>
 </tr>
 <tr>
  <td>Mean</td> <td>Sigma</td> <td>Mean</td> <td>Sigma</td>
 </tr>
 <tr>
</thead>
<tbody>
 <tr>
    <td>1</td> <td>Test 1</td> <td>Celcius</td> <td>0.23</td> <td>10.44</td> <td>1.22</td> <td>13.13</td>
 </tr>
 <tr>
    <td>2</td> <td>Test 2</td> <td></td> <td></td> <td></td> <td>0.16</td> <td>0.31</td>
 </tr>
 <tr>
    <td>3</td> <td></td> <td></td> <td>0.13</td> <td>11.33</td> <td></td> <td></td>
 </tr>
 <tr>
    <td>4</td> <td>Test Blah</td> <td>Km</td> <td></td> <td></td> <td></td> <td></td>
 </tr>
</tbody>
</table




Thanks in advance for your help!

Kind regards,
  Prem

---
Prem Gurbani
Software Engineer,WW Mfg
Analog Devices Inc.
Reply With Quote
  #2 (permalink)  
Old June 12th, 2004, 05:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

I think you may have a problem because you can't use one stylesheet for multiple XML files simultaneously. You can reuse stylesheets; however, it won't mix result sets as you have shown above. Can you combine the XML files?

Brian
Reply With Quote
  #3 (permalink)  
Old June 12th, 2004, 06:29 PM
Registered User
 
Join Date: Jun 2004
Location: Raheen, Limerick, Ireland.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I couldn’t find anything about multiple XML sources either.

So I thought of developing a "higher-level" XML file (index.xml), which handles all different sources.. Then, one XSLT file accesses this “top level” xml which contains all the file names, etc. It seems to work, more or less, although I believe it’s too complex, and difficult to handle and maintain..

So I don’t know whether there is a cleaner and more elegant way of doing this… I’m with XSLT only a couple of weeks and I thought I may not be approaching it correctly.


The index.xml looks as follows:

<tables>
        <table id="Main">
                <head id="Test_No">
                        <source>definitions.xml</source>
                        <subhead>Test_No</subhead>
                </head>
                <head id="25degC">
                        <source>experiments.xml</source>
                        <subhead>Mean</subhead>
                        <subhead>Sigma</subhead>
                </head>
                <head id="50degC">
                        <source>experiments.xml</source>
                        <subhead>Mean</subhead>
                        <subhead>Sigma</subhead>
                </head>
....

(also, here I don't know how to make the head id dynamic, i.e. accept any temperature value, and either 1 or 4 different values)




Then, an XSLT. This is a simplified extract:

- <xsl:template name="showtable_values">
  <xsl:param name="tableid" />
- <xsl:for-each select="document('definitions.xml')/tests/test">
  <xsl:sort select="@number" order="ascending" />
  <xsl:variable name="mynumber" select="@number" />
- <xsl:variable name="myhref">
- <xsl:choose>
+ <xsl:when test="$tableid = 'Main'">
  <xsl:value-of select="concat('#Product_Anova', $mynumber)" />
  </xsl:when>
  </xsl:choose>
  </xsl:variable>
- <TR>
- <TD>
- <xsl:call-template name="showtable_number">
  <xsl:with-param name="href" select="$myhref" />
  <xsl:with-param name="text_link" select="$mynumber" />
  <xsl:with-param name="tableid" select="$tableid" />
  <xsl:with-param name="number" select="$mynumber" />
  </xsl:call-template>
  </TD>
- <TD>
  <xsl:value-of select="Name" />
  </TD>
- <TD>
  <xsl:value-of select="Unit" />
  </TD>
- <xsl:for-each select="document('../index.xml')/tables/table[@id = $tableid]/head">
  <xsl:variable name="myheadid" select="@id" />
  <xsl:variable name="mysource" select="source" />
- <xsl:if test="string($mysource) != 'definitions.xml'">
- <xsl:choose>
- <xsl:when test="string($mysource) = 'experiments.xml'">
  <xsl:variable name="mysourcenow" select="document(string($mysource))/*/test[@number = $mynumber]/*" />
- <xsl:for-each select="subhead">
  <xsl:variable name="mysubhead" select="text()" />
- <TD>
- <xsl:call-template name="showtable_matchvalue">
  <xsl:with-param name="matchsource" select="$mysourcenow" />
  <xsl:with-param name="matchsubhead" select="$mysubhead" />
  </xsl:call-template>
  </TD>
  </xsl:for-each>
  </xsl:when>
  </xsl:choose>
  </xsl:if>
  </xsl:for-each>
  </TR>
  </xsl:for-each>
  </xsl:template>



Sorry for the large amount of code.


Thanks again,
  Prem



---
Prem Gurbani
Software Engineer,WW Mfg
Analog Devices Inc.
Reply With Quote
  #4 (permalink)  
Old June 23rd, 2004, 05:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm to have a look at the same issue. I found this link, maybe you too can get something from the examples:

http://www.topxml.com/xsltStylesheet...erversion=true

:-)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update DB by passing ID number jonsey Classic ASP Professional 1 April 11th, 2007 07:05 PM
grouping multiple xml files in one file bcogney XSLT 3 April 21st, 2006 03:58 AM
Importing Multiple files in Multiple tables Versi Suomi Access 6 June 1st, 2005 08:47 AM
Finding the most common value in an XML set Teeeeej XSLT 7 December 17th, 2004 08:59 AM
Common question, not so common answer? flyin ADO.NET 5 March 24th, 2004 06:50 PM



All times are GMT -4. The time now is 11:52 PM.


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