473,379 Members | 1,283 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Struggling with xsl:sort

Hi,

I'm having difficulty building an XLST file that allows me to sort a list of
log records. I put together an XSL file that allows me to output a copy of
the input file and then I attempted to sort it. Eventually I want to filter
it based on the "when" element (and/or others) but I cannot proceed until I
get the sort to work. I have tried several approaches (specific XPATHs,
data-type on the sort) none of which have worked (or have produced unsorted
output, and this is the one I feel is simplest and most logical. What am I
doing wrong?

Any assistance appreciated.

..js driver
var xmlRetDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlRetDoc.async = false
xmlRetDoc.load("newinput.xml")

// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM");
xsl.async = false;
xsl.load("XSL Log Report.xsl");

// Transform
var newxml = new ActiveXObject("Microsoft.XMLDOM");
newxml.loadXML(xmlRetDoc.transformNode(xsl));
newxml.save("newxml.xml");

Input file:
<?xml version="1.0" encoding="UTF-16"?>
<ATfES>
<log type="I" level="4000"
id="000000000001-5b96fa11-efd2-4cf0-86cb-dab84186fac6">
<when>2004-10-29T15:21:18</when>
<user>VIC\ATSystem</user>
</log>
<log type="I" level="4000"
id="000000000002-46be7d71-800f-49e2-ab0f-ed14a35e197c">
<when>2004-10-29T15:21:17</when>
<user>VIC\ATSystem</user>
</log>
<log type="I" level="4000"
id="000000000003-86a927bf-b06f-42cc-8f3b-7f76231271d5">
<when>2004-10-29T15:21:15</when>
<user>VIC\ATSystem</user>
</log>
<log type="I" level="3000"
id="000000000004-bbec8881-f09f-442a-8d98-d2f04f02c695">
<when>2004-10-29T15:21:20</when>
<user>VIC\ATSystem</user>
</log>
<log type="I" level="3000"
id="000000000005-f83ba729-29a2-4dd3-b97c-25919d926d59">
<when>2004-10-29T15:21:19</when>
<user>VIC\ATSystem</user>
</log>
</ATfES>

XSL File 1 - this one successfully copies the input file to a new output
file
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

XSL File 2 - creates no output - added select on "log", sort on "when" and
template for "log"
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates select="log">
<xsl:sort select="when"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="log">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
Jul 20 '05 #1
1 2045
On Sat, 30 Oct 2004 06:17:31 GMT, Derek Tinney <dt*****@shaw.ca> wrote:
Hi,

I'm having difficulty building an XLST file that allows me to sort a list of
log records. I put together an XSL file that allows me to output a copy of
the input file and then I attempted to sort it. Eventually I want to filter
it based on the "when" element (and/or others) but I cannot proceed until I
get the sort to work. I have tried several approaches (specific XPATHs,
data-type on the sort) none of which have worked (or have produced unsorted
output, and this is the one I feel is simplest and most logical. What am I
doing wrong?

XSL File 2 - creates no output - added select on "log", sort on "when" and
template for "log"
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates select="log">
<xsl:sort select="when"/>
</xsl:apply-templates>
</xsl:template>


Hi,

The problem is not the sort but the apply-templates.

Use this and you will get the output you want:

<xsl:apply-templates select="*/log">
<xsl:sort select="when"/>
</xsl:apply-templates>
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jarle Presttun | last post by:
Hi, Sometimes I display values by combining information from different sections in the xml, like I do with gradeText in the student template bellow. Is it possible to sort on gradeText when I...
2
by: R | last post by:
Hello everybody. I was sorting all my XML data with for-each and sort. But there were few cases that I didn't want to sort my data. so I added nosort attribute - if given and set to '1' don't...
3
by: Tjerk Wolterink | last post by:
I posted my problem earlier, but i simplified the examples, and i know what the cause of the problem is, but i dont know the solution, my xml file: <?xml version="1.0" encoding="ISO-8859-1"?>...
6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
2
by: jobooker | last post by:
I'm having issues sorting. The short description is, how do I set the select attribute of xsl:sort to be the value of an xsl:variable? The longer description follows: What I want to do is to be...
3
by: davisford | last post by:
Hi, If I have something like this: <parents> <parent name="foo"> <children> <child>fred</child> <child>barney</child> <child>wilma</child>
2
by: ajc308 | last post by:
I have an XML document that looks like the following: <root name="PlanRepository"> <directory name="connoraj"> <directory name="single_run1"> <file>insidebox.txt</file> ...
1
by: =?Utf-8?B?SWxsdXN0cmlz?= | last post by:
I'm hoping someone can help me with what looks like a very simple problem. My output does not sort the languages alphabetically as I would expect. Can someone inspect my XSLT please? TIA!! ...
7
by: otis | last post by:
Hi all, This is a small issue to make things prettier, but we all know how important that can be! I had an xsl:if to check if a node was the last one in a collection of nodes and if it was a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.