how do I test for current XSL template?

Discussion in 'XML' started by festo, Apr 19, 2007.

  1. festo

    festo Guest

    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
     
    festo, Apr 19, 2007
    #1
    1. Advertising

  2. festo wrote:
    > 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...?)

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Apr 19, 2007
    #2
    1. Advertising

  3. festo

    festo Guest

    On Apr 19, 11:31 am, Joseph Kesselman <>
    wrote:
    > festo wrote:
    > > 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...?)
    >
    > --
    > Joe Kesselman / Beware the fury of a patient man. -- John Dryden



    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.
     
    festo, Apr 19, 2007
    #3
  4. > 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.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Apr 19, 2007
    #4
  5. Joseph Kesselman wrote:
    >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.


    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, Apr 25, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ray Tayek
    Replies:
    3
    Views:
    542
    Ray Tayek
    Nov 30, 2003
  2. Vijay singh
    Replies:
    1
    Views:
    455
    Martin Honnen
    Nov 4, 2004
  3. Replies:
    1
    Views:
    3,695
    A. Bolmarcich
    May 27, 2005
  4. lele1979

    xsl:Include e xsl:call-template

    lele1979, Nov 6, 2006, in forum: XML
    Replies:
    1
    Views:
    576
  5. lele1979

    xsl:Include e xsl:call-template

    lele1979, Nov 6, 2006, in forum: XML
    Replies:
    0
    Views:
    377
    lele1979
    Nov 6, 2006
Loading...

Share This Page