Re: [xsl] Is there a better way to produce a single html via XSLT from multiple xml files ?

Subject: Re: [xsl] Is there a better way to produce a single html via XSLT from multiple xml files ?
From: Kamal <kbhatt@xxxxxxxxx>
Date: Sat, 22 Mar 2008 23:33:03 +1100
Z W wrote:
Hi

Newbie to XSLT.

I'm using Ant's xslt task to invoke Saxon 9.
I have 2 input xml files, each in a different directory.
I have 1 xls for both.
Problem:
a) I got stuck at trying to find the minimun and maximum of each attribute.
From what I understand, you are trying to get the minimum and maximum of a result. This XPath:

<xsl:value-of select="document($previousJTL)/Results/*[@label ='Init']/@time" />

Doesn't do that.

The easiest (at least to program) way of getting the min and max would be to simply sort the values then get the min/max. This is my example. Turns out the FAQ (http://www.dpawson.co.uk/xsl/sect2/N6461.html#d10052e632) has a similar example. I simplified your case (removed the document), but this is enough to get you started.

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


<xsl:output method="text" />
<xsl:template match="Results">
<xsl:apply-templates select="sampleResult[@label ='Init']" mode="max">
<xsl:sort select="@time" order="descending" data-type="number" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="sampleResult" mode="max">
<xsl:if test="position() = 1">
<xsl:value-of select="@time"/>
</xsl:if>


</xsl:template>

</xsl:stylesheet>

FYI, thanks to your question I found out how twisted the interaction between position, apply-templates and sort really is. Namely, sorting occurs after the XPath has matched not before. That makes sense when you think about it, but still it is debatable whether this is for the best. It definitely makes this processing more difficult.

b) Because of (a), I thought I should make 2 separate calls to the
same xls for the 2 xml files, whose outputs are html files
But this create the problem to find a way to combine these 2 html files.

Is there a better way to do this - ie could I just use a single xsl
and produce results from 2 different xml inputs
I have also posted an earlier question about min, max problem.

Thank you very much for your help.

In one of your other posts, you mention you are using Ant.

My recommendation here (if it is still relevant) is to not try and combine two HTML outputs, but combine the inputs. You mentioned using Ant, I would have a two pass process, first pass combines the two files into one, the second parse does whatever you really want to do. I do something similar with XSDs. It shouldn't be too hard to do. As I said, don't know if you need to actually do that.

Current Thread