472,348 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 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 2356
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...
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...
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...
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...
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...
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...
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...
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...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.