xsl-list
[Top] [All Lists]

RE: alternative for modes

2004-02-13 09:09:07
OOPS, I got it now about FXSL!

As said, I can only use XSLT1.0 functions, but I always thought FXSL was
some kind of extension which is a layer above EXSL(.org) to be able to pass
templates as parameter. So I thought FXSL uses EXSL-functions.

I studied now how it actually works, and I was indeed wrong. It does some
neat tricks with (unique) namespaces (well for me it is :p), to accomplish
my goal.

So basically I'll have to make 2 templates: one for red output, one for blue
output, both in some unique namespace. I will pass both templates to the
giveCarsSorted-template, which will sort the cars by owner and call the
given (by parameter) template.

About the real example: sorry I really can't give it, it's a school exercise
and I don't think I'm allowed to paste my code here. However, the given
example (cars, always sort them by owner and output them first in blue, then
in red, then in ...) is almost the same of what I want to: in several
sections of my output file, I need the same ordering-strategy, but different
things has to be done by the ordered list (output in blue, red, ...) in each
section.

Anyway, I'll try the FXSL solution out, I think I understand it, so I don't
think that will be a big problem.

Thanks for your time,

Peter

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Dimitre
Novatchev
Sent: vrijdag 13 februari 2004 9:40
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] alternative for modes 

Peter,

I do not understand what really is the problem. I am inclined to believe
that if it is that difficult to describe this problem, then most probably
you do not have a problem at all?

Or could you, please, provide a really concise and compact example that
illustrates the problem well?

This is a very frequent situation on this list. There are a lot of very
knowledgeable people, who can help and are willing to help.

When this help is not given, it is mostly due to the fact that the OP
couldn't express the problem well so that it would be understood
correctly.

Most people hate guessing and even Jeni is sometimes clueless... :o)

Now, my guess is that you need to be passed as parameter a list of actions
(templates) to be performed. This is exactly what FXSL empowers you to do
with ease.

Waiting for a well-defined problem.

Cheers,

Dimitre Novatchev
FXSL developer, 

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html



----------- Peter Billen wrote:
 RE: [xsl] alternative for modes | RE: [xsl] alternative for modes  
Oki I think it's time for an example :) Imagine:

<streetrace> 
        <car> 
                <owner> ...</owner>
                ...
        </car> 
        <car> 
                <owner> ...</owner>
                ...
        </car> 
        ...
</streetrace> 

Now imagine you want to print out all the cars of the streetrace: first
all
in red, then in blue, sorted by the owner of the car(in my example of
course, everything is a bit more complicated, especially the sorting
code).
The best I came up with, is the following:

<xsl:template match="streetrace> 
        <!-- print cars in blue !--> 
        <xsl:call-template name="giveCarsSorted"> 
                <xsl:with-param name="mode" select="'blue'"/> 
        </xsl:call-template> 
        <!-- in red !--> 
        <xsl:call-template name="giveCarsSorted"> 
                <xsl:with-param name="mode" select="'red'"/> 
        </xsl:call-template> 
</xsl:template> 

<xsl:template name="giveCarsSorted"> 
        <xsl:param name="mode"/> 

        <xsl:apply-templates>  // this will go to each <car>-element
                <xsl:sort select="car/owner"/>  // sort on <owner> in <car>
                <xsl:with-param name="mode" select="$mode"/>  // propagate
$mode
        </xsl:apply-templates> 
</xsl:template> 

<xsl:template match="car"> 
        <xsl:param name="mode"/> 

        <xsl:if test="$mode = 'blue'"> 
                <font color="blue"> <xsl:value-of select="."/></font><br/>
        </xsl:if> 
        <xsl:if test="$mode = 'red'"> 
                <font color="red"> <xsl:value-of select="."/></font><br/>
        </xsl:if> 
</xsl:template> 

I hope I didn't make any big mistakes, since I haven't tested it myself.

In my opinion the problem is: I need the same sorting more than once, so
it's a good idea to put it in a separate template (the sorting in my code
is
a bit more complicated). However, all the situations where I need the
sorting, DO NOT depend on any specific value(s) of the <car> -element or
one
or more of his children. So I THINK creating 'conditional templates' won't
help since there is no condition, which can be deduced from the
tree-structure, at all.

Thanks for your time,

Peter


 


__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>