473,327 Members | 1,892 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,327 software developers and data experts.

[xsl] sort & modulo

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"?>
<?xml-stylesheet type="text/xsl" href="datastyle.xsl"?>
<data xmlns="http://tjerk.com">
<item>a1</item>
<item>b2</item>
<item>c3</item>
<item>d4</item>
<item>e5</item>
<item>f6</item>
<item>a0</item>
</data>
If i would sort the text items elements i would place the
last item a0 at the beginning. But i am also
using the modulo operator to create a table like structure:

The xsl file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:tjerk="http://tjerk.com"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>
<xsl:param name="cols" select="3"/>

<xsl:template match="/tjerk:data">
<data>
<xsl:for-each select="./tjerk:item[(position() mod $cols)=1]">
<xsl:sort data-type="text" select="tjerk:item" order="descending" />
<tr>
<xsl:apply-templates select="."/>
<xsl:apply-templates select="following-sibling::tjerk:item[position() &lt;
$cols]"/>
</tr>
</xsl:for-each>
</data>
</xsl:template>

<xsl:template match="tjerk:item">
<td><xsl:value-of select="."/></td>
</xsl:template>
</xsl:stylesheet>

---

The output is:
-
<data>
<tr><td>a0</td></tr>
<tr><td>a1</td><td>b0</td><td>c3</td></tr>
<tr><td>d4</td><td>e5</td><td>f6</td></tr>
</data>
-

But i want the output to be like this:
-
<data>
<tr><td>a0</td><td>a1</td><td>b0</td></tr>
<tr><td>c3</td><td>d4</td><td>e5</td></tr>
<tr><td>f6</td></tr>
</data>
-

The problem is the sort element in the foreach loop,

how can i solve this???
Help is much appreciated.
Jul 20 '05 #1
3 2433
Use two pass transformation -- the first to sort and the second to group.

Cheers,
Dimitre Novatchev

"Tjerk Wolterink" <tj***@wolterinkwebdesign.com> wrote in message
news:d4**********@netlx020.civ.utwente.nl...
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"?>
<?xml-stylesheet type="text/xsl" href="datastyle.xsl"?>
<data xmlns="http://tjerk.com">
<item>a1</item>
<item>b2</item>
<item>c3</item>
<item>d4</item>
<item>e5</item>
<item>f6</item>
<item>a0</item>
</data>
If i would sort the text items elements i would place the
last item a0 at the beginning. But i am also
using the modulo operator to create a table like structure:

The xsl file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:tjerk="http://tjerk.com"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>
<xsl:param name="cols" select="3"/>

<xsl:template match="/tjerk:data">
<data>
<xsl:for-each select="./tjerk:item[(position() mod $cols)=1]">
<xsl:sort data-type="text" select="tjerk:item" order="descending" />
<tr>
<xsl:apply-templates select="."/>
<xsl:apply-templates select="following-sibling::tjerk:item[position() &lt;
$cols]"/>
</tr>
</xsl:for-each>
</data>
</xsl:template>

<xsl:template match="tjerk:item">
<td><xsl:value-of select="."/></td>
</xsl:template>
</xsl:stylesheet>

---

The output is:
-
<data>
<tr><td>a0</td></tr>
<tr><td>a1</td><td>b0</td><td>c3</td></tr>
<tr><td>d4</td><td>e5</td><td>f6</td></tr>
</data>
-

But i want the output to be like this:
-
<data>
<tr><td>a0</td><td>a1</td><td>b0</td></tr>
<tr><td>c3</td><td>d4</td><td>e5</td></tr>
<tr><td>f6</td></tr>
</data>
-

The problem is the sort element in the foreach loop,

how can i solve this???
Help is much appreciated.

Jul 20 '05 #2
Dimitre Novatchev wrote:
Use two pass transformation -- the first to sort and the second to group.

Cheers,
Dimitre Novatchev

Ok but can i do that with just one invocation of the xsltprocessor??
I do not have acces to the xslt processor, and it just calls the xml with xsl
transformation one time, so is there no other solution??
Or can i do a twopass transformmation in one xsltransformation??

"Tjerk Wolterink" <tj***@wolterinkwebdesign.com> wrote in message
news:d4**********@netlx020.civ.utwente.nl...
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"?>
<?xml-stylesheet type="text/xsl" href="datastyle.xsl"?>
<data xmlns="http://tjerk.com">
<item>a1</item>
<item>b2</item>
<item>c3</item>
<item>d4</item>
<item>e5</item>
<item>f6</item>
<item>a0</item>
</data>
If i would sort the text items elements i would place the
last item a0 at the beginning. But i am also
using the modulo operator to create a table like structure:

The xsl file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:tjerk="http://tjerk.com"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>
<xsl:param name="cols" select="3"/>

<xsl:template match="/tjerk:data">
<data>
<xsl:for-each select="./tjerk:item[(position() mod $cols)=1]">
<xsl:sort data-type="text" select="tjerk:item" order="descending" />
<tr>
<xsl:apply-templates select="."/>
<xsl:apply-templates select="following-sibling::tjerk:item[position() &lt;
$cols]"/>
</tr>
</xsl:for-each>
</data>
</xsl:template>

<xsl:template match="tjerk:item">
<td><xsl:value-of select="."/></td>
</xsl:template>
</xsl:stylesheet>

---

The output is:
-
<data>
<tr><td>a0</td></tr>
<tr><td>a1</td><td>b0</td><td>c3</td></tr>
<tr><td>d4</td><td>e5</td><td>f6</td></tr>
</data>
-

But i want the output to be like this:
-
<data>
<tr><td>a0</td><td>a1</td><td>b0</td></tr>
<tr><td>c3</td><td>d4</td><td>e5</td></tr>
<tr><td>f6</td></tr>
</data>
-

The problem is the sort element in the foreach loop,

how can i solve this???
Help is much appreciated.


Jul 20 '05 #3

"Tjerk Wolterink" <tj***@wolterinkwebdesign.com> wrote in message
news:d4**********@netlx020.civ.utwente.nl...
Dimitre Novatchev wrote:
Use two pass transformation -- the first to sort and the second to group.

Cheers,
Dimitre Novatchev

Ok but can i do that with just one invocation of the xsltprocessor??


Yes.
I do not have acces to the xslt processor, and it just calls the xml with
xsl transformation one time, so is there no other solution??
Or can i do a twopass transformmation in one xsltransformation??


Yes.

The result of the first transformation is produced within the content (body)
of an xsl:variable.

Then this RTF is converted to an intermediary tree using the xxx:node-set()
extension function (available with almost every XSLT processor).

Then the second transformation is applied on this intermediary tree.

See for example:

"A Generic template for multi-pass processing (Was: Re: Applying two
transformations consecutively)"

http://www.biglist.com/lists/xsl-lis.../msg01152.html
Cheers,
Dimitre Novatchev.
Jul 20 '05 #4

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

Similar topics

0
by: Michael Fork | last post by:
Note: I pasted the code the attachments as plain text after the message (I wasn't able to post it with an attachment...) Attached are the XSL and XML files that I am having problems with. I am...
2
by: Sebek | last post by:
Hello, I'm transforming a XML document in XHTML but I have problems using sub-strings, it will be clearer with an exemple: What I have: <form...
0
by: tsirman | last post by:
hello well i have a problem with an xsl file. i create two columns of my data. a have the above code and i want to have my data sorted.i managed this only for the first column of the file....
0
by: tsirman | last post by:
hello i have the above code and i can't sort my data in the second column. if someone did not understood i want to say that i have splitted my data in two columns so now i want these data to be...
6
by: tsirman | last post by:
hello can i put in an xsl file variables from php??? well i have 15 xsl files which have many "<a href.........." with the url of the project. so if i want to make my project portable i must have...
1
by: DrTebi | last post by:
Hello, I have the following problem: I used to "encode" my email address within links, in order to avoid (most) email spiders. So I had a link like this: <a...
0
by: Steve | last post by:
To begin, I'm using Adobe's Spry Framework for all my data in my XML page, it saves space and code on the HTML. Well, I want to make it so that certain cells are chosen and are either highlighted...
11
by: coflo | last post by:
Hello I would like to replace an a href link that is provided in the RSS below with my own link. The link that I am looking to replace is defined in the <description> tag within the RSS. Im...
2
by: felciano | last post by:
Hello -- I am trying to use XSL to process Amazon wishlist data to sort the results by type (Apparel, then Books, then DVDs, etc). Amazon's web services chunk up results in multiple pages of...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.