xsl-list
[Top] [All Lists]

RE: Forbidden with several xsl:attribute from xsl:apply-templates?

2003-06-30 10:48:36
I guess the problem is in the "..." that you haven't shown us. It is
probably writing elements or text nodes to the output. You can't write
an attribute after writing a text node or element child to the same
parent.

Michael Kay

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Erik Beijnoff
Sent: 30 June 2003 16:09
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Forbidden with several xsl:attribute from 
xsl:apply-templates?


I'm having a problem with two consecutive <xsl:apply-templates> that
both should output <xsl:attribute>. I'm having a feeling that 
I'm trying
to do a forbidden thing, but I figured I'd turn to the list 
to be sure.

Im running FOP togheter with Xalan to create PDF:s. So the 
first step is
the transformation of xml via xslt to xsl:fo then to pdf via FOP.
However, problems occur.

The execution is as follows:

1. A template gets called when an element with a "class" attribute is
the active node.
2. The first apply-templates applies any template that is specific for
elements with that name
3. The second apply-templates applies any template that is 
specific for
elements with that class name

In point three, the output "Cannot add attribute font-family 
after child
nodes or before an element is produced. Attribute will be 
ignored." gets
output at the command line.

I'm aware that all <xsl:attribute> must appear in template data before
any child nodes, but I'd figured that since both 
<apply-templates> only
outputs <xsl:attribute>, it should work. Well, it seems like 
it perhaps
doesn't work that way after all.


<!-- The template where the error occurs-->
<xsl:template match="p">
   <fo:block>
      <!-- First apply works -->
     <xsl:apply-templates select="." mode="elementselection"/>

     <!-- Second gets it attribute output ignored -->
     <xsl:apply-templates select="." mode="classselection"/>

     <xsl:apply-templates/>
   </fo:block>
</xsl:template>       

<!-- Attributes for a specific type of element is output -->
<xsl:template match="h1" mode="elementselection">     
   <xsl:attribute name="font-family">sans-serif</xsl:attribute>
   <xsl:attribute name="font-size">20pt</xsl:attribute>
   ...
</xsl:template>

<!-- Attributes for an element with a specific class is output -->
<xsl:template match="*[(_at_)class = 'leadtext']" mode="classselection">
   <xsl:attribute 
name="border-bottom-color">sans-serif</xsl:attribute>

   <xsl:attribute name="border-bottom-width">0.5pt</xsl:attribute>
   ...
</xsl:template>

Regards Erik Beijnoff
erik(_at_)beijnoff(_dot_)com
erik(_at_)addsystems(_dot_)com



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>