Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2006, 08:03 AM
Authorized User
 
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default More parameterization ...

Hallo All,

I have an XML file with various hierarchy levels that I would like to get the user to navigate. I am using a key technique to group the data and it works fine ...

The user can select a PLANT and can view a consolidation of data for the teams that belong to the plant. That's great.

Now I would like to parameterize the whole thing so that, instead of selecting a PLANT the user can select a BUSINESS UNIT and can then see data for all the PLANTs in that BU. That's no problem if it's hard-coded but ...

When I try to plop in parameters the whole thing stops working. For example:

<xsl:apply-templates select="xmlout[(PERIOD=$pper and PLANT_CODE=$pplnt)]" mode="body">

... works fine ($pper supplies the PERIOD filter and $pplnt the PLANT). However, if I try to parameterize this ...

<xsl:apply-templates select="xmlout[(PERIOD=$pper and $pfieldname=$pplnt)]" mode="body">

... with $pfieldname representing the text PLANT_CODE, then it all stops working. I have tried adding quote marks but this also doesn't work.

So my big question now is: Am I trying to ask too much of XSL? Or am I approaching the problem in the wrong way?

If I can't parameterize the selection of field names like this, then it will mean that I have to build almost identical XSL templates over and over again. Arrgghh!

Maybe I have just misunderstood and XSL has a special way of doing this? I hope so.

Any tips would really help me on this one.

Regards,
Alan Searle.

 
Old September 28th, 2006, 09:36 AM
Authorized User
 
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Success! Sort of ...

It's probably not how it is supposed to be done but I have incorporated a variable which, when requeried (with javascript), flips the 'apply-templates' clause (using xsl:when). It is not exactly what I wanted but it sort of works (although speed is a bit sluggish).

Anyway, I'll do more experimenting and will report back to the forum.

Regards,
Alan.

 
Old September 28th, 2006, 09:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XSLT is not a macro language. Variable represent values, not bits of text that you can substitute textually into an expression. If you have a value 3 or "London" in an expression like [x = 3] or [x = "London"] then you can replace the value with a variable reference. In these examples you can also replace x with a variable $X, but if the value of $X is "x", then you are doing a quite different test: instead of testing whether the element x is equal to 3 or "London", you are testing whether the String "x" is equal to 3 or London (which it isn't).

Similarly if you write X/$Y (which is actually allowed in XPath 2.0), and the value pf $Y is "fred", then this is the same as writing X/"fred", not the same as X/fred.

To replace an element name by a variable that holds the element name, change X/Y to X/*[name()=$VAR].

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 29th, 2006, 04:05 AM
Authorized User
 
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

Thanks for your general comments: They prompted me to return to the books and to 'mug up' on the logic. That helps a lot.

> To replace an element name by a variable that holds the element
> name, change X/Y to X/*[name()=$VAR].

This snippet of syntax really got me moving: Now I can start flipping my display much more efficiently. Fantastic!

Thanks very much.

Regards,
Alan.










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.