Loading ...
Sorry, an error occurred while loading the content.

Xalan problem with xsl:param

Expand Messages
  • splifke
    Hello all, last week I designed an xslfo-stylesheet to convert an xml-document to a pdf-document. To perform the transformation I used FOP from the
    Message 1 of 2 , Sep 10, 2002
    • 0 Attachment
      Hello all,

      last week I designed an xslfo-stylesheet to convert an xml-document
      to a pdf-document. To perform the transformation I used FOP from the
      command-line. Now I am trying to embed the transformation into java
      code, but trying to do this, I run into the following problem:

      "javax.xml.transform.TransformerException: xsl:param is not allowed
      in this position in the stylesheet!
      at org.apache.xalan.processor.StylesheetHandler.error
      (StylesheetHandler.java:876)

      This error is produced on code like this (the xsl:param definition in
      the templates is the problem):

      <xsl:template match="table">
      <xsl:if test="caption">
      <fo:table-caption xsl:use-attribute-sets="table.data.caption">
      <fo:block start-indent="0em">
      <xsl:apply-templates select="caption"/>
      </fo:block>
      </fo:table-caption>
      </xsl:if>
      <fo:table xsl:use-attribute-sets="table.data" >
      <xsl:param name="frame">
      <xsl:choose>
      <xsl:when test="@frame">
      <xsl:value-of select="@frame"/>
      </xsl:when>
      <xsl:otherwise>
      <xsl:text>box</xsl:text>
      </xsl:otherwise>
      </xsl:choose>
      </xsl:param>

      <xsl:param name="rule">
      <xsl:choose>
      <xsl:when test="@rules">
      <xsl:value-of select="@rules"/>
      </xsl:when>
      <xsl:otherwise>
      <xsl:text>all</xsl:text>
      </xsl:otherwise>
      </xsl:choose>
      </xsl:param>

      <xsl:call-template name="table.frame_rules">
      <xsl:with-param name="frame" select="$frame"/>
      <xsl:with-param name="rule" select="$rule"/>
      </xsl:call-template>
      </fo:table>
      </xsl:template>

      <xsl:template name="table.frame_rules">
      <xsl:param-variable name="frame"/>
      <xsl:param-variable name="rule"/>

      <xsl:choose>
      <xsl:when test="$frame='void'">
      <xsl:attribute name="border-bottom-style">none</xsl:attribute>
      <xsl:if test="count(ancestor::tr/preceding-sibling::*)=0 or
      $rule='cols' or $rule='none'">
      <xsl:attribute name="border-top-style">none</xsl:attribute>
      </xsl:if>
      ...
      </xsl:choose>
      </xsl:template>

      What I do not understand is how to pass parameters if the previous
      example is not valid. I found similar examples on several sites (for
      example http://www.xml.com/lpt/a/2001/02/07/trxml9.html). On the
      contrary I found out that the xsl:param tag is only allowed within
      xsl:stylesheet and xsl:transform.

      Does anybody know how I can pass parameters from templates to other
      templates without producing an invalid xsl-file?

      Thank you for your reply!

      Ben van Mol
    • G. Ken Holman
      ... I suspect you have a basic misunderstanding about parameters. They only parameterize either template rules or the entire stylesheet ... they cannot
      Message 2 of 2 , Sep 10, 2002
      • 0 Attachment
        At 2002-09-10 08:29 +0000, splifke wrote:
        >"javax.xml.transform.TransformerException: xsl:param is not allowed
        >in this position in the stylesheet!
        > at org.apache.xalan.processor.StylesheetHandler.error
        >(StylesheetHandler.java:876)
        >
        >This error is produced on code like this (the xsl:param definition in
        >the templates is the problem):
        >
        ><xsl:template match="table">
        > <xsl:if test="caption">
        > <fo:table-caption xsl:use-attribute-sets="table.data.caption">
        > <fo:block start-indent="0em">
        > <xsl:apply-templates select="caption"/>
        > </fo:block>
        > </fo:table-caption>
        > </xsl:if>
        > <fo:table xsl:use-attribute-sets="table.data" >
        > <xsl:param name="frame">

        I suspect you have a basic misunderstanding about parameters. They only
        parameterize either template rules or the entire stylesheet ... they cannot
        parameterize a portion of the stylesheet.

        If you are just trying to set $frame and $rule, then use <xsl:variable>
        which is allowed pretty well anywhere in a template rule.

        ><xsl:template name="table.frame_rules">
        > <xsl:param-variable name="frame"/>
        > <xsl:param-variable name="rule"/>

        These are improperly named XSLT instructions ... they should be <xsl:param>.

        >What I do not understand is how to pass parameters if the previous
        >example is not valid.

        Unfortunately, your example isn't valid.

        >I found similar examples on several sites (for
        >example http://www.xml.com/lpt/a/2001/02/07/trxml9.html).

        I could not find your use of these instructions on that page ... I think
        Bob has it all right on that page, and knowing Bob he would get it right as
        he is good at what he does.

        > On the
        >contrary I found out that the xsl:param tag is only allowed within
        >xsl:stylesheet and xsl:transform.

        I feel you have been misinformed.

        >Does anybody know how I can pass parameters from templates to other
        >templates without producing an invalid xsl-file?

        Check again what Bob has to say ... it looks fine to me.

        I hope this helps.

        ......................... Ken

        --
        Upcoming hands-on in-depth Europe: Sep 18-Sep 20,2002
        XSLT/XPath and XSL-FO North America: Sep 30-Oct 4,2002

        G. Ken Holman mailto:gkholman@...
        Crane Softwrights Ltd. http://www.CraneSoftwrights.com/f/
        Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995)
        ISBN 0-13-065196-6 Definitive XSLT and XPath
        ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
        ISBN 1-894049-10-1 Practical Formatting Using XSL-FO
        XSL/XML/DSSSL/SGML/OmniMark services, books (electronic, printed),
        articles, training (instructor-live,Internet-live,web/CD,licensed)
        Next public training: 2002-09-11,13,18,19,30,10-03,12-08
      Your message has been successfully submitted and would be delivered to recipients shortly.