473,606 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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:styleshe et version="1.0"
xmlns:tjerk="ht tp://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:i tem" order="descendi ng" />
<tr>
<xsl:apply-templates select="."/>
<xsl:apply-templates select="followi ng-sibling::tjerk: item[position() &lt;
$cols]"/>
</tr>
</xsl:for-each>
</data>
</xsl:template>

<xsl:template match="tjerk:it em">
<td><xsl:valu e-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 2452
Use two pass transformation -- the first to sort and the second to group.

Cheers,
Dimitre Novatchev

"Tjerk Wolterink" <tj***@wolterin kwebdesign.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:styleshe et version="1.0"
xmlns:tjerk="ht tp://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:i tem" order="descendi ng" />
<tr>
<xsl:apply-templates select="."/>
<xsl:apply-templates select="followi ng-sibling::tjerk: item[position() &lt;
$cols]"/>
</tr>
</xsl:for-each>
</data>
</xsl:template>

<xsl:template match="tjerk:it em">
<td><xsl:valu e-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 xsltransformati on??

"Tjerk Wolterink" <tj***@wolterin kwebdesign.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:styleshe et version="1.0"
xmlns:tjerk=" http://tjerk.com"
xmlns:xsl="ht tp://www.w3.org/1999/XSL/Transform">

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

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

<xsl:templa te match="tjerk:it em">
<td><xsl:valu e-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***@wolterin kwebdesign.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 xsltransformati on??


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
3480
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 trying to extract the stock information after having downloaded the HTML and converted to XML (well-formed HTML) using XSL and XPATH and am unable. I am basing what I have done so far off of...
2
4347
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 href="identification.php?PHPSESSID=134134&page=2&param=3" > </form> what I want:
0
1155
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. -------------------------------------- <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
0
1222
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 sorted. ------------------------------------ <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="code">
6
1663
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 a config file in php probably and there put the full url of my project and not edit every time all the 15 xsl files....
1
11431
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 href="mailto:DrTebi@yahoo.com">DrTebi</a> This would work like a regular mailto link in any browser, but wouldn't be visible to spiders if they don't have a function to decode it.
0
1307
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 with green or red depending on a condition. ====================================XML====================================== <?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet type="text/xsl" href="bowlgames.xsl"?> <bowlgames>
11
4931
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 guessing I need to use some sort of function in combination with regex. I am able to create a regex to find and replace the a href link very easily; however, using regex in combination with a find and replace in XSL i am extremly novice. I am wanting...
2
2485
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 fixed size, e.g. 55 items gets returned in 5 XML pages of 10 items and a 6th of 5 items. Each page is returned from a distinct URL call with a PageNum parameter. I've been trying to adapt a technique described at...
0
7981
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8462
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8320
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6803
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5994
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5470
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3952
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1315
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.