how do I test for current XSL template?

F

festo

Hi guys,

I need to print a different footer depending on the template being
printed. How do I test for the current template being processed in
XSLT?

Thanks,

fes
 
J

Joseph Kesselman

festo said:
I need to print a different footer depending on the template being
printed. How do I test for the current template being processed in
XSLT?

There's no "what template is being processed" query in XSLT. You can use
parameters and modes to explicitly pass context information down to
other templates invoked from this one... but since I don't understand
from the description what you're actually trying to do, I can't advise
you on how to achieve it.

(In fact the concept of "current template" is somewhat flaky. Since
templates may be nested either as a result of an apply-templates action
or because they were explicitly invoked via call-templates. There may be
many "current" templates stacked up at any given time. If you mean the
most recent template, you don't have to test for it since you're in it...?)
 
F

festo

There's no "what template is being processed" query in XSLT. You can use
parameters and modes to explicitly pass context information down to
other templates invoked from this one... but since I don't understand
from the description what you're actually trying to do, I can't advise
you on how to achieve it.

(In fact the concept of "current template" is somewhat flaky. Since
templates may be nested either as a result of an apply-templates action
or because they were explicitly invoked via call-templates. There may be
many "current" templates stacked up at any given time. If you mean the
most recent template, you don't have to test for it since you're in it...?)


heres what I am trying to do.

<xsl:template name="template1Name">
.....
</xsl: template>

<xsl:template name="template2Name">
.....
</xsl: template>

I am already printing page number and I want to also print the
template name dynamically.
So I want to test which template is currently being processed while
doing the pagination,
then print its name in the footer together with page#.

eg template2Name page 2

thanks.
 
J

Joseph Kesselman

I am already printing page number

Printing and pagination and footers aren't XSLT concept. They're handled
by whatever your next stage or processing is (XSL-FO processor or
browser or whatever else is consuming XSLT's output).

So what you need to do is find out what syntax the markup system you're
generating uses to alter the footer -- assuming this can be done on a
dynamic basis, which may not be correct -- and have the template
generate the appropriate markup to do so. You can't retrieve the
template's name; you have to hand-code that same string in the
appropriate place in the template's body.
 
J

Joe Kesselman

Joseph said:
You can't retrieve the
template's name; you have to hand-code that same string in the
appropriate place in the template's body.

.... Or, just to point out an alternative: You could write a stylesheet
for styling stylesheets which implements a syntax what retrieves the
template's name. See my two-part article on DeveloperWorks for an
illustration of what techniques would be involved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top