Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 29th, 2006, 06:54 PM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Checking if a specific template exists

Hey everyone,

Been spending two days trying to figure this one out, and thought I'd ask here to see if anyone could give me a definite answer on this one.

I am not sure, if this can be done in XSLT (I'm not that experienced with it), but here is my problem :

I want to call a template that may or may not have been included, if it hasn't it should resolve to another template (that is always there).

As there are no proper way of doing exception handling in XSLT, I thought maybe there was a work around or a way to emulate that kind of behaviour.

I'm using XSLT 1.0 (Sablotron).

Any feedback will be highly appreciated.

Thanks
Reply With Quote
  #2 (permalink)  
Old September 30th, 2006, 02:37 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I suspect that you're making a classic and easy mistake, which is to have a general-purpose module that includes/imports special purpose modules (conditionally). That's the wrong way around for XSLT: the special purpose module (say S) should import the general-purpose code (say G). Then G can do a call-template on a named template N; if S contains an implementation of N this will be the one chosen, otherwise it can fall back to another version of N provided by G. Because S imports G, the version in S has higher import precedence and will be chosen in preference.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old September 30th, 2006, 07:52 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Michael,
Thank you for your reply.

I understand what you mean, and I did encounter that very problem at the very beginning. I suppose if I explain the issue, it might shed light on what I am really trying to do.

XSL I am trying to do is serving to be templating engine for a framework, I am currently working on.

So far this is how it works:

(S) contains 2 templates "frontend" and "admin" templates which are defined by name without a matching pattern. S also includes a "run.xsl" (R), which has a template with a matching pattern to everything.
(R) also includes 2 skins. a Frontend skin and a Backend skin.
Based on the XML structure (R) can determine which skin to call.

In the skin which is a template and renders out, there is a call-template tag that will call either Frontend or Admin (depending on which skin, backend will call admin).

Now all of this works nicely, until I realised that I had to add an additional template in (S) a "superadmin" template. Some of the modules in the framework may or may not have a superadmin function, which enables them to see more information than a normal admin would, and therefore the visual layout would be different.
However, a superadmin may also run a module as an admin, because that particular module may not have a superadmin function and will represent the information equally for admins and superadmins.

In the XML root tag you have an attribute called "user" and a value saying if its admin or superadmin. Based on that I imagined that I could do something like this

(pseudocode)

Try to call template with match pattern [@user='superadmin']
if it doesnt exist call template with match pattern [@user='admin' or @user='superadmin']

I hope this sheds more light on what I am trying to do, and I might have approached this from a bad angle. I am open to any suggestions.

Thanks.
Reply With Quote
  #4 (permalink)  
Old October 1st, 2006, 03:14 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Try to call template with match pattern [@user='superadmin'] if it doesnt exist call template with match pattern [@user='admin']

This sounds like something that could be achieved fairly easily using apply-templates and template rules. R should do apply-templates select="/rootelement/@user", and S determines what happens when this is done. The basic principle is that your first choice template [@user='superadmin'] must have a higher import precedence or priority than your fallback template [@user='admin], and you need to arrange the import precedence (or priorities) to achieve this.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search specific data from specific columns yogeshyl SQL Language 1 January 16th, 2008 11:12 AM
Copy specific data in specific cells of sheet2 yogeshyl Excel VBA 1 May 14th, 2007 07:40 AM
Checking to see if record exists EmmaGale Classic ASP Basics 6 March 14th, 2006 02:39 AM
calling one template in other template VijayKumar XSLT 3 September 15th, 2005 11:12 AM
checking file exists on remote server pete_m Classic ASP Basics 11 August 2nd, 2004 02:35 AM



All times are GMT -4. The time now is 12:42 PM.


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