[xsl] How to order this with xslt

T

Tjerk Wolterink

Don't thinkt it is possible, but maybe someone knows how to do this.

I have an xml file like this:

---
<?xml version="1.0" encoding="ISO-8859-1"?>
<xc:xcontent xmlns:xc="http://www.wolterinkwebdesign.com/xml/xcontent" xmlns="http://www.w3.org/1999/xhtml" module="agenda">
<xc:subset offset="0" max="10" count="3"/>
<xc:agendapunt>
<xc:id>1</xc:id>
<xc:title type="string"><![CDATA[Tjerk Jarig]]></xc:title>
<xc:date type="date">
<xc:day>02</xc:day>
<xc:month>08</xc:month>
<xc:year>2005</xc:year>
<xc:display>2005-08-02</xc:display>
</xc:date>
<xc:content type="html">
Ja dan ben ik jarig, blij blij blij<br/>
</xc:content>
</xc:agendapunt>

<xc:agendapunt>
<xc:id>2</xc:id>
<xc:title type="string"><![CDATA[Radstake]]></xc:title>
<xc:date type="date">
<xc:day>18</xc:day>
<xc:month>02</xc:month>
<xc:year>2005</xc:year>
<xc:display>2005-02-18</xc:display>
</xc:date>
<xc:content type="html">
Avondje stake<br/>
</xc:content>
</xc:agendapunt>
<xc:agendapunt>
<xc:id>3</xc:id>

<xc:title type="string"><![CDATA[buizen]]></xc:title>
<xc:date type="date">
<xc:day>15</xc:day>
<xc:month>02</xc:month>
<xc:year>2006</xc:year>
<xc:display>2006-02-15</xc:display>
</xc:date>

<xc:content type="html">
buizen
</xc:content>
</xc:agendapunt>
</xc:xcontent>
---


And a stylesheet like this (onlt this template):

---
<xsl:template match="/xc:xcontent">
<page:page type="module">


<page:form-messages multiple="agendapunt"/>
<page:button-new module="agenda" multiple="agendapunt"/>
<page:form-new multiple="agendapunt"/>
<page:form-edit multiple="agendapunt"/>


<xsl:for-each select="xc:agendapunt">
<page:form>
<page:header><xsl:value-of select="xc:title"/></page:header>
<page:data>
<page:name>Datum</page:name>
<page:value><xsl:value-of select="xc:date/xc:display"/></page:value>
</page:data>
<page:data>
<page:text-name>Content</page:text-name>
<page:text-value>
<xsl:value-of select="xc:content"/>
<page:button-edit-delete module="agenda" id="{./xc:id}" multiple="agendapunt"/>
</page:text-value>
</page:data>
</page:form>
</xsl:for-each>
</page:page>
</xsl:template>
---


But what i want is the following:

I want the xc:agendapunt ordered by their <xc:data element. So that the first data is shown in the first <page:form output and the last
data is shown at the bottom.

Note that the xsl stylesheet knows some integer variables that represent the current date: $time_day $time_year $time_month.
You can use them. I do'nt know how to solve this.
 
J

Joris Gillis

Tempore 19:40:10 said:
I want the xc:agendapunt ordered by their <xc:data element. So that the first data is shown in the first <page:form output and the last
data is shown at the bottom.

Note that the xsl stylesheet knows some integer variables that represent the current date: $time_day $time_year $time_month.
You can use them. I do'nt know how to solve this.

Hi,

In Xpath 2.0, you'll have plenty of date functions to solve this properly.
But since so much data is provided, you can do it also in XSLT1.0.

Because 'xc:display' seems to be of format 'YYYY-MM-DD', you can use stringwise sort:

<xsl:for-each select="xc:agendapunt">
<xsl:sort select="xc:date/xc:display"/>
....
</xsl:for-each>

If the 'xc:display' can't be trusted to have this structure, you can still use the order data in a numeric sort:

<xsl:for-each select="xc:agendapunt">
<xsl:sort select="xc:date/xc:year" data-type="number"/>
<xsl:sort select="xc:date/xc:month" data-type="number"/>
<xsl:sort select="xc:date/xc:day" data-type="number"/>
....
</xsl:for-each>


regards,
 
T

Tjerk Wolterink

Joris said:
Tempore 19:40:10, die Tuesday 15 February 2005 AD, hinc in foro



Hi,

In Xpath 2.0, you'll have plenty of date functions to solve this properly.
But since so much data is provided, you can do it also in XSLT1.0.

Because 'xc:display' seems to be of format 'YYYY-MM-DD', you can use
stringwise sort:

<xsl:for-each select="xc:agendapunt">
<xsl:sort select="xc:date/xc:display"/>
...
</xsl:for-each>

If the 'xc:display' can't be trusted to have this structure, you can
still use the order data in a numeric sort:

<xsl:for-each select="xc:agendapunt">
<xsl:sort select="xc:date/xc:year" data-type="number"/>
<xsl:sort select="xc:date/xc:month" data-type="number"/>
<xsl:sort select="xc:date/xc:day" data-type="number"/>
...
</xsl:for-each>


regards,


Thanks for your input!
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top