Subject: RE: [xsl] alternative for modes From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx> Date: Fri, 13 Feb 2004 11:51:16 +0100 |
> -----Original Message----- > From: Peter Billen > Hi, Picked up on this thread a little late, so maybe I've missed out on a few essential details, but anyway > The first template doesn't work: $mode is just a string to know what we > want/what we are doing when we are in the <car>-element, nothing more. > Can you explain the 'just-a-string' part a bit more? (Does this merely mean that the value of the variable does not come from the source XML tree, and basically bears no relation to it whatsoever?) Say you define a few global elements in a separate namespace in your stylesheet, like: <xsl:stylesheet ... xmlns:mode="dummy:namespace" exclude-result-prefixes="mode"> ... <mode:color val="blue" /> <mode:color val="red" /> <mode:color val="green" /> You could use these to for-each over, and apply-templates passing their @val in as parameter (see below) > About the second template: so actually there hasn't changed anything since > my 'original example', except the fact that the if-test is moved into the > predicate of the xpath-expression, and 3 'new' templates which all matches > the element <car>, but each of them has a different mode (green, red and > blue). So the condition to see why we are in the <car>-element and the > simulation of multiple modes (propagating mode from <streetrace> > ==> sorting > template ==> <car>) is still there? > I'm curious as to why you would insist on performing the sort in a separate template, where you could as easily do: <xsl:template match="streetrace"> <xsl:variable name="vcars" select="car" /> <xsl:for-each select="document('')//mode:color"> <xsl:variable name="vmode" select="@val" /> <xsl:apply-templates select="$vcars"> <xsl:sort select="owner" /> <xsl:with-param name="mode" select="$vmode" /> </xsl:apply-templates> </xsl:for-each> </xsl:template> <xsl:template match="car"> <xsl:param name="pmode" select="NONE" /> <font color="{document('')//mode:color[@val=$pmode]/@val}"> <xsl:value-of select="." /> </font> </xsl:template> This would lead you to the same result as sequentially calling templates with different mode-params in your example, the cars will be sorted by owner each time, and you get to keep the reference to the 'condition why you are in the car template', I believe... (if I get your intention correctly) In this particular case, the AVT would obviously return the value of the mode parameter itself, but you could expand the structure of the mode:color elements further to provide a convenient mapping of some sort... > I'm starting to believe there is no real better solution for > this; at least > if we are only using XSLT1.0 functions. > Hmm.. toying with namespaces is definitely legal (cfr. Dimitre's FXSL), and document() is a standard 1.0 function, not? Just goes to show: no lack of possibilities :) Cheers, Andreas XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] alternative for modes, Wendell Piez | Thread | RE: [xsl] alternative for modes, Jim Fuller |
RE: [xsl] xsl conditional: finding , Michael Kay | Date | [xsl] creating multiple pdf-files f, Kloeck, Erwin |
Month |