Conditional call-template -broken in 2.6

Discussion in 'XML' started by terry.jeske@gmail.com, Apr 4, 2005.

  1. Guest

    Hello,

    In xalan 2.41 we were able to conditionally call a template. This
    appears broken in 2.6. I did glance at the call-template specfications
    but did not see anything that would point to this being a feature or a
    change to follow a standard. The problem is that if the called
    template is not included in xslt pass, I get:

    javax.xml.transform.TransformerException: ElemTemplateElement error:
    "your missing template name here".

    We are upgrading our app to java 1.5, and have made extensive use of
    this type of call which allow us to have leverage common code for
    presentation and admin pages. Below is a simplified code snipet. If it
    runs for you, make sure you check your xalan version by running java
    org.apache.xalan.Version.

    Any insight into why this is happening would be most appreciated.

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.w3.org/1999/xhtml">

    <xsl:eek:utput method="xml"
    media-type="text/html"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    doctype-system="DTD/xhtml1-strict.dtd"
    encoding="ISO-8859-1" />

    <xsl:variable name="testCall" select="'false'"/>
    <xsl:template match="/">
    <html>
    <head>
    <title>Conditional call-template test</title>
    </head>

    <body>
    <xsl:if test="$testCall = 'true'">
    <xsl:call-template name="foobar"/>
    </xsl:if>
    No errors. Go home and relax
    </body>
    </html>
    </xsl:template>

    <!-- uncomment this and it will work -->
    <!--xsl:template name="foobar">
    <b>hi</b>
    </xsl:template-->

    </xsl:stylesheet>
     
    , Apr 4, 2005
    #1
    1. Advertising

  2. wrote:
    : Hello,

    : In xalan 2.41 we were able to conditionally call a template. This
    : appears broken in 2.6. I did glance at the call-template specfications
    : but did not see anything that would point to this being a feature or a
    : change to follow a standard. The problem is that if the called
    : template is not included in xslt pass, I get:

    : javax.xml.transform.TransformerException: ElemTemplateElement error:
    : "your missing template name here".

    : We are upgrading our app to java 1.5, and have made extensive use of
    : this type of call which allow us to have leverage common code for
    : presentation and admin pages. Below is a simplified code snipet. If it
    : runs for you, make sure you check your xalan version by running java
    : org.apache.xalan.Version.

    : Any insight into why this is happening would be most appreciated.

    : <?xml version="1.0" encoding="ISO-8859-1"?>
    : <xsl:stylesheet version="1.0"
    : xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    : xmlns="http://www.w3.org/1999/xhtml">

    : <xsl:eek:utput method="xml"
    : media-type="text/html"
    : doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    : doctype-system="DTD/xhtml1-strict.dtd"
    : encoding="ISO-8859-1" />

    : <xsl:variable name="testCall" select="'false'"/>
    : <xsl:template match="/">
    : <html>
    : <head>
    : <title>Conditional call-template test</title>
    : </head>

    : <body>
    : <xsl:if test="$testCall = 'true'">
    : <xsl:call-template name="foobar"/>
    : </xsl:if>
    : No errors. Go home and relax
    : </body>
    : </html>
    : </xsl:template>

    : <!-- uncomment this and it will work -->
    : <!--xsl:template name="foobar">
    : <b>hi</b>
    : </xsl:template-->
    :
    : </xsl:stylesheet>

    it appears that in the earlier version of xalan, calling an undefined
    template would be a runtime error. In other words the template name is
    not looked up until you try use the template. (and since you don't ever
    try to actually use the temlate then you don't get the runtime error).

    it appears that in the new version, referencing an undefined template is a
    compile time error. In other words the template name is looked up while
    the template is being prepared for use (i.e. compile time.) For most
    people this would be considered an advantage. Typos in template names
    will be detected ahead of time, thereby avoiding hard to track down
    run-time errors.

    I assume that you could simply define do-nothing versions of the templates
    for the style sheets that don't really use them.

    you might "include" or "import" the defintions, and then play with
    relative paths so as to suck in the alternate versions depending on who is
    using the style sheet.

    $0.02

    --

    This space not for rent.
     
    Malcolm Dew-Jones, Apr 5, 2005
    #2
    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. Alec S.
    Replies:
    10
    Views:
    10,170
    Alec S.
    Apr 16, 2005
  2. Gawain
    Replies:
    9
    Views:
    334
    red floyd
    Jan 14, 2008
  3. Steven D'Aprano

    Why are "broken iterators" broken?

    Steven D'Aprano, Sep 21, 2008, in forum: Python
    Replies:
    8
    Views:
    661
  4. Cameron Simpson

    Re: Why are "broken iterators" broken?

    Cameron Simpson, Sep 22, 2008, in forum: Python
    Replies:
    0
    Views:
    591
    Cameron Simpson
    Sep 22, 2008
  5. Fredrik Lundh

    Re: Why are "broken iterators" broken?

    Fredrik Lundh, Sep 22, 2008, in forum: Python
    Replies:
    0
    Views:
    608
    Fredrik Lundh
    Sep 22, 2008
Loading...

Share This Page