Need help with XSL

Discussion in 'XML' started by marktm@gmail.com, Jan 29, 2006.

  1. Guest

    I want to sort the my XML by Montn and the day. I am using this as my
    XSL. What am I doing wrong?


    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="event">
    <xsl:copy>
    <xsl:apply-templates>
    <xsl:sort select="events/event/day"/>
    </xsl:apply-templates>
    </xsl:copy>
    </xsl:template>

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

    </xsl:stylesheet>

    <?xml version="1.0" encoding="iso-8859-1"?>
    <GALLERY>

    <openerText><p>Lorem ipsum dolor sit amet, consectetuer adipiscing
    elit. Vivamus aliquet. Suspendisse erat dolor, sollicitudin non,
    dignissim vulputate, imperdiet ac, enim. Nam malesuada neque eget
    ante.</p><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    Vivamus aliquet <a href="#">wits aertr</a> dsakjwer
    alier.</p></openerText>
    <events>
    <event>
    <eventid>1</eventid>
    <title>Cut Glass: Exploring Dimension</title>
    <month>January</month>
    <day>4</day>
    <year>2006</year>
    <time>11:30AM</time>
    <eventShortDetail>Short Detail</eventShortDetail>
    <eventThumbnail>event_thumbnail.jpg</eventThumbnail>
    <artists>
    <artist>
    <artistName>artist name 1</artistName>
    <artistLink>link1</artistLink>
    </artist>
    <artist>
    <artistName>artist name 2</artistName>
    <artistLink>link2</artistLink>
    </artist>
    </artists>
    </event>
    <event>
    <eventid>1</eventid>
    <title>Cut Glass: Exploring Dimension</title>
    <month>January</month>
    <day>8</day>
    <year>2006</year>
    <time>11:30AM</time>
    <eventShortDetail>Short Detail</eventShortDetail>
    <eventThumbnail>event_thumbnail.jpg</eventThumbnail>
    <artists>
    <artist>
    <artistName>artist name 1</artistName>
    <artistLink>link1</artistLink>
    </artist>
    <artist>
    <artistName>artist name 2</artistName>
    <artistLink>link2</artistLink>
    </artist>
    </artists>
    </event>
    <event>
    <eventid>1</eventid>
    <title>Cut Glass: Exploring Dimension</title>
    <month>January</month>
    <day>3</day>
    <year>2006</year>
    <time>11:30AM</time>
    <eventShortDetail>Short Detail</eventShortDetail>
    <eventThumbnail>event_thumbnail.jpg</eventThumbnail>
    <artists>
    <artist>
    <artistName>artist name 1</artistName>
    <artistLink>link1</artistLink>
    </artist>
    <artist>
    <artistName>artist name 2</artistName>
    <artistLink>link2</artistLink>
    </artist>
    </artists>
    </event>

    </events>

    </GALLERY>
    , Jan 29, 2006
    #1
    1. Advertising

  2. Soren Kuula Guest

    wrote:
    > I want to sort the my XML by Montn and the day. I am using this as my
    > XSL. What am I doing wrong?


    Hi,

    You are forgetting to tell us what kind of result you expected, and what
    kind of result you got.

    Soren
    Soren Kuula, Jan 29, 2006
    #2
    1. Advertising

  3. Eric Amick Guest

    On 28 Jan 2006 21:56:52 -0800, wrote:

    >I want to sort the my XML by Montn and the day. I am using this as my
    >XSL. What am I doing wrong?


    I assume you mean month and day.....

    >
    >
    ><xsl:stylesheet version="1.0"
    >xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    >
    ><xsl:template match="event">
    > <xsl:copy>
    > <xsl:apply-templates>
    > <xsl:sort select="events/event/day"/>


    The current nodeset at this point is the children of <event>, so it's no
    surprise this doesn't work. You need to be sorting event nodes, so
    specifying the sort within the event template rule is too late.

    > </xsl:apply-templates>
    > </xsl:copy>
    > </xsl:template>


    Replace the above rule with this (untested), and you should be a lot
    better off:

    <xsl:template match="events">
    <xsl:copy>
    <xsl:apply-templates select="event">
    <xsl:sort select="month"/>
    <xsl:sort select="day" data-type="number"/>
    </xsl:apply-templates>
    </xsl:copy>
    </xsl:template>

    --
    Eric Amick
    Columbia, MD
    Eric Amick, Jan 29, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Flood
    Replies:
    0
    Views:
    1,002
    Kevin Flood
    Sep 8, 2004
  2. Kevin Flood
    Replies:
    1
    Views:
    2,702
    Kevin Flood
    Sep 13, 2004
  3. Klaus Friese
    Replies:
    0
    Views:
    451
    Klaus Friese
    Nov 22, 2004
  4. Replies:
    1
    Views:
    3,568
    A. Bolmarcich
    May 27, 2005
  5. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Help with XSL/XSL:FO for producing revision indicator bar in document.

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Apr 28, 2006, in forum: XML
    Replies:
    6
    Views:
    560
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
    May 3, 2006
Loading...

Share This Page