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.
|