xsl-list
[Top] [All Lists]

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

2008-03-22 05:33:34
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/*[(_at_)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[(_at_)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.


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--