[xsl] Muenchian Grouping: Not coyping all elements

Subject: [xsl] Muenchian Grouping: Not coyping all elements
From: Sato_Alex@xxxxxxx
Date: Wed, 30 Aug 2006 13:12:43 -0400
I'm using Apache Software Foundation's http://xml.apache.org/xalan-j
 
I have a standard docbook book/chapter/refentry structure. I'm trying to
group the refentry elements into sections using the role attribute on each
refentry as the section/title--so the new structure would be
book/chapter/section/refentry. I have 2 chapters and the refentry id
attribute values begin with either "comp" for the "Components Reference"
chapter or "actn" for the "Actions Reference chapter--so I use "comp" and
"actn" to determine which chapter to put the refentry elements into.
 
The problem is that only 49 new sections are created, whereas there should
be 73. Also, the input file has be 2168, but the output file only has 1680
refentry elements. If I switch the positions of the chapters in the input
file, then the second one is still truncated.
 
Thanks--Alex
 
Here's my stylesheet:
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">  <xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes" doctype-public="-//Arbortext//DTD DocBook XML V4.0//EN"
doctype-system="axdocbook.dtd"/>  <xsl:key name="task-sections"
match="refentry" use="@role"/>  <xsl:template match="/">
  <xsl:element name="book">
   <xsl:apply-templates select="book/chapter"/>
  </xsl:element>
 </xsl:template>
 <xsl:template match="chapter">
   <xsl:variable name="id-first-string">
    <xsl:choose>
     <xsl:when test="title='Actions Reference'">
      <xsl:text>actn</xsl:text>
     </xsl:when>
     <xsl:when test="title='Components Reference'">
      <xsl:text>comp</xsl:text>
     </xsl:when>
    </xsl:choose>
   </xsl:variable>
  <xsl:element name="chapter">
   <xsl:copy-of select="title"/>
   <xsl:copy-of select="partintro"/>
   <xsl:for-each
select="refentry[generate-id()=generate-id(key('task-sections', @role)[1])
and starts-with(@id,$id-first-string)]">
    <xsl:element name="section">
     <xsl:element name="title">
      <xsl:choose>
       <xsl:when test="@role != 0">
        <xsl:value-of select="@role"/>
       </xsl:when>
       <xsl:when test="@role = 0">
        <xsl:text>Need to be categorized</xsl:text>
       </xsl:when>
      </xsl:choose>
     </xsl:element>
     <xsl:for-each
select="key('task-sections',@role)[starts-with(@id,$id-first-string)]">
      <xsl:copy-of select="."/>
     </xsl:for-each>
    </xsl:element>
   </xsl:for-each>
  </xsl:element>
 </xsl:template>
</xsl:stylesheet>

Current Thread