Struggling with xsl:sort

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Derek Tinney

    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.XMLDO M")
    xmlRetDoc.async = false
    xmlRetDoc.load( "newinput.x ml")

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

    // Transform
    var newxml = new ActiveXObject(" Microsoft.XMLDO M");
    newxml.loadXML( xmlRetDoc.trans formNode(xsl));
    newxml.save("ne wxml.xml");

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


  • Joris Gillis

    #2
    Re: Struggling with xsl:sort

    On Sat, 30 Oct 2004 06:17:31 GMT, Derek Tinney <dtinney@shaw.c a> wrote:
    [color=blue]
    > 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:styleshe et 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>
    >[/color]

    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

    Comment

    Working...