 |
| 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
|
|
|
|

October 5th, 2006, 09:54 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Opening with a parameter ...
I have an XSL template that needs to call other XSL files. At the moment the scenario looks like this (classic parent-child relationships):
Two XML files exist:
A. Team.xml (select team, display customers)
B. Customer.xml (Select customer, display orders)
Each file has an XSL template (e.g. customer.xsl) declared in the header and both work fine at the moment.
However, I would like to do the following ...
1. A user browses a list of teams (team.xml, with team.xsl declared in the header of the xml file)
2. The user selects a team and views the customers for that team (view provided by team.xsl)
3. The user clicks on a customer and the customer.xml opens with the customer.xsl automatically applying a filter for the selected customer.
I can include hot-links (href) in my xml/xsl which will open the other xml (customer.xml) but I need to pass over a parameter and kick off the filter which selects the required customer.
So my question is whether I am following the right approach? Or maybe this is all a bit too 'sequential' and I should instead be using XSL in a different way?
Any tips on how I should best structure this and whether I can call up XML/XSL files with a parameter would be very helpful.
Regards and many thanks,
Alan Searle
PS: This must be an issue which comes up quite often so maybe someone can point me towards a good HOWTO or tutorial?
|
|

October 5th, 2006, 10:00 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
You don't actually say whether you're running the transformations client side or server side, but at this level of abstraction, the design is fine either way.
The only thing is that when invoking a transformation using the <?xml-stylesheet?> PI, you can't supply parameters. So you'll have to write some script to do the invocation. The details then depend on what environment(s) you want it to run in.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

October 5th, 2006, 10:10 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Michael,
> You don't actually say whether you're running the transformations
> client side or server side
The files will be on a server but the server will play no part in the processing. So I imagine that's 'client side', isn't it?
> but at this level of abstraction, the design is fine either way.
Great. Thanks for confirming that.
> The only thing is that when invoking a transformation using the <?
> xml-stylesheet?> PI, you can't supply parameters. So you'll have to
> write some script to do the invocation. The details then depend on
> what environment(s) you want it to run in.
My XSL contains javascript to activate filtering and other functions. Is this the script that you mean? Can I hang a command in there somewhere? Or is there another method/language that should be used?
Thanks very much for your help.
Regards,
Alan.
|
|

October 5th, 2006, 11:07 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
You stated in your post that a user browses a list of teams (team.xml) and team.xsl is declared in the header. Does that mean you're using a processing instruction, xsl-stylesheet, or not?
Either way you need to call customer xsl programatically, you can't use another processing-instruction. You can then add a parameter before the actual transform. There is no way to do this that works across all browsers so you need to specify which browsers you are targeting before I can give you any more details.
For example you can use zXml from Nicholas Zakas to target the latest IE, Mozilla, Safari and Opera although some advanced features of XSLT, such as the document() function, won't all work.
--
Joe ( Microsoft MVP - XML)
|
|

October 6th, 2006, 02:52 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Joe,
>You stated in your post that a user browses a list of teams
>(team.xml) and team.xsl is declared in the header. Does that mean
>you're using a processing instruction, xsl-stylesheet, or not?
Yes, that's the way I'm doing it.
>Either way you need to call customer xsl programatically, you can't
>use another processing-instruction. You can then add a parameter
>before the actual transform. There is no way to do this that works
>across all browsers so you need to specify which browsers you are
>targeting before I can give you any more details.
The pages will be used internally and so every user will have IE 6.0 SP2.
You say I need to call the XML/XSL files programmatically? How would this look? For example, I might have a href clause calling the second XML (customer.xml) file (linked to customer.xsl). So how would the programmatic call of customer.xml apply or initiate the filter (for example 'Smith & Co.')?
Maybe you have a little 'mini example' of such a call?
Many thanks,
Alan Searle
|
|

October 6th, 2006, 06:43 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
I can give some pseudo code, to fill in the blanks see the msxml sdk. As i said you cannot use a linked transform. You need to create something like customer.html and call it passing the filter, e.g. customer.html?teamId=3.
Code:
functions:
getCustomerDoc - retrieves msxml2.domdocument.3.0 and loads cutomer.xml
getCustomerXslt - loads customer.xsl into another dom document and creates Msxml2.XSLTemplate.3.0 for processing
code:
getCustomerDoc()
getCustomerXslt()
parse location.search to the teamId
use addParameter on Xslt to set teamId
Perform transform
Apply results to suitable part of page using innerHTML.
--
Joe ( Microsoft MVP - XML)
|
|
 |