Re: [xsl]Problem with Position()?

Subject: Re: [xsl]Problem with Position()?
From: Alice Ju-Hsuan Wei <ajwei@xxxxxxxxxxx>
Date: Sat, 13 Oct 2007 15:59:04 -0400
Quoting "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>:

there is a new problem. I have a "id()" function embedded in my
document that goes along in my document which is now not displaying
no matter if I used Saxon 8 or XSLT proc. With 8, it tells me this
error: Description: An attribute node (class) cannot be created
after the children of the containing element. What I am supposed to
have is some kind of display of who recorded the item.

Your error is being triggered somewhere other than the code you cut and pasted into your posting.

The error is quite explicit:  somewhere you are adding an attribute
to the result tree, but at the time you are doing so you have already
added child nodes to the most recently added element.  You can only
add attributes to an element before you start adding the elements
children.

Nowhere in the code you posted are you adding an attribute to an
element, so the problem is elsewhere.

XSLT:

<xsl:template match="collection">
  <div><p/>
           <span class="character">
               <xsl:apply-templates select="id(@recorder)"/>
</span>
</div>
</xsl:template>

<xsl:template match="book">

<div>
  <xsl:apply-templates select="./@author"/>,
  <i><xsl:apply-templates select="./@title"/></i>.
   (<xsl:apply-templates select="./@topic"/>)
  <xsl:template match="p">
       <xsl:choose>
           <xsl:when test="count(preceding-sibling::p) != 1">
               <xsl:call-template name="rend"/>
               <xsl:apply-templates/>
           </xsl:when>
           <xsl:otherwise>
               <p>
                   <xsl:call-template name="rend"/>
                   <xsl:apply-templates/>
               </p>
           </xsl:otherwise>
       </xsl:choose>
   </xsl:template>

My guess is that it might be there, where you are pushing the topic attribute. How are you handling the matching of the topic attribute? If when you catch it you are adding it to the result tree, then that is not a valid place to do so because the last thing added to the result tree is the left parenthesis in the text node, not an element.

But that is just a guess since you don't have everything exposed in
your post.

I have commented everything in my document except for these sections, and it still displays this error. In case it is the child, does not the "attribute" be considered as the same node?


Thanks again.

Alice

Current Thread