Re: [xsl] Sorting data after transformation is done

Subject: Re: [xsl] Sorting data after transformation is done
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Tue, 29 Apr 2008 17:02:11 +0200
Jean-Yves Avenard schrieb:
I am working on some xmltv files. An xmltv file (as described in
www.xmltv.org) is a XML file containing TV programme information.
The programme listings look like this:
 <tv>
<programme channel="tpg.aljazeera" start="20080430040000 +0100"
stop="20080430043000 +0100"> [...]

I'm working with TV data, too.


As you can see, the programme contains one attribute: start which is a
date in the format YYYYMMDDHHMMSS [+-]XXXX where XXXX is the timezone.

I have written an XSLT template (I've attached the code below) that
converts that date to UTC as the xmltv file will contain various
programme, all in different timezone depending on the source.

What I'm trying to achieve, is sort the XML file based on the start
attribute, but *after* it has been converted to UTC

Can't you just preprocess the data in order to add an attribute @ts holding a good old UNIX timestamp, and another attribute, if needed, holding a value for display?

The way I would convert my date, with my template/function is:
	<xsl:variable name="utcstart">
		<xsl:call-template name="UTCDate">
			<xsl:with-param name="DateTime" select="@start"/>
		</xsl:call-template>
	</xsl:variable>

Is this something that would be possible with XSLT?
if not, could you suggest a work around ?

I think this could work, but I'd embed the XSLT part in a host language like Perl, PHP, or Java, and then use mktime and strftime (or their Java equivalents) to handle dates and times.

-- My UTC convert template: Unfortunately, I want this to run in my
web browser, and I haven't found one compatible with XSLT 2.0, so I
had to do everything by hand.

I think this is, indeed, unfortunate. Are you sure you can't do part of the work on the server side? There, you may find better tools for the job. XSLT, even 1.0, certainly is great, but it's not the only tool in the box. In the web browser, however, you can't escape to host languages as you can on the server side. So there's a lot of things that are very hard to tackle in the browser.

And I think we'll have to wait for a couple of years to see widespread
support for 2.0 in web browsers.

Even on the server side, if you use Perl or PHP or Python, you'll very
likely use LibXSLT, which means XSLT 1.0.

[ snipped 250+ lines of XSLT ]

I haven't checked this XSLT - but it's so much easier in other
languages, which have all the functionality you need to handle dates.

http://de3.php.net/manual/en/xsltprocessor.registerphpfunctions.php
http://search.cpan.org/dist/XML-LibXSLT/LibXSLT.pm - register_function

Best,

Michael

Current Thread