Need help with XSL

M

marktm

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>
 
S

Soren Kuula

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
 
E

Eric Amick

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top