On 13 Mar 2009, at 17:18, u671296 wrote:

Hi

To start off, a very brief answer to this:

With the xml & code below I get the following error (from FOP) at the marked
location:
xsl:with-param is not allowed in this position in the stylesheet!


That is expected. xsl:call-template will result in nodes being created in the result tree. You cannot use it as a function that returns a value to pass to another xsl:call-template. XSLT 2.0 would offer xsl:function for that purpose, but before you run off upgrading the stylesheet...

<snip />
My XML can contain optional attributes for tables, things like border-width, border-style etc. I need to supply default values if the attribute does not exist and as there could be many optional parameters I don't want to use
XSL:choose statements to cope with the variations.

Instead I'm trying to use a get_params template to see what parameter is in question, return the value of the supplied attribute else the default which is then used in a with_params statement. The code below is a cludge to try
and get it working for one attribute (border-style) only.

Strictly speaking, off-topic for the list, but I notice you are missing out on a very powerful feature of XSLT, called "attribute sets".

You could easily define a set of default attributes for various types of formatting objects (block, table, table-cell... etc.)

Since you specify the attributes from the explicit values coming from your source XML directly on the literal result element or via xsl:attribute, those values will always take precedence over values that are defined in any applied attribute sets.

Create the desired attribute set as a top-level element in the stylesheet:

<xsl:attribute-set name="table-border-defaults">
  <xsl:attribute name="border">1pt solid black</xsl:attribute>
  ...
</xsl:attribute>

and a bit further on:
...
<fo:table ...>
   <xsl:apply-templates select="@border | @border-style" />
   ...
   <fo:table-body xsl:use-attribute-sets="table-border-defaults">
     <xsl:apply-templates select="../@border | ../@border-style" />
...

<xsl:template match="@*">
<xsl:attribute name="name(.)"><xsl:value-of select="." /></ xsl:attribute>
</xsl:template>


The simple template below is probably a bit too generic, but could prove enough to get you started. The point is that, if the source table-node contains a "border" attribute, that one will prevail on the fo:table-body. If not, then the one from the xsl:attribute-set is used.


Regards

Andreas

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to