469,282 Members | 1,846 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

[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 2181
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Michael Fork | last post: by
reply views Thread by tsirman | last post: by
reply views Thread by tsirman | last post: by
6 posts views Thread by tsirman | last post: by
reply views Thread by Steve | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.