limitations of xslt

Subject: limitations of xslt
From: Earl Bingham <earl@xxxxxxxxxxxxxx>
Date: Sat, 23 Oct 1999 15:43:11 -0700 (PDT)
Here is my input file:

<?xml version="1.0"?>
<textItems>
   <title>Here is my first title!</title>
   <bullet>first group first bullet</bullet>
   <bullet>first group second bullet</bullet>
   <normal>first group first normal</normal>
   <bullet>first group third bullet</bullet>
   <title>Here is my second title!</title>
   <bullet>second group first bullet</bullet>
   <normal>second group first normal</normal>
   <bullet>second group second bullet</bullet>
   <bullet>second group third bullet</bullet>
</textItems>

here is my stylesheet

<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";
                xmlns:xt="http://www.jclark.com/xt";
                extension-element-prefixes="xt">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="textItems">
  <result>
    <xsl:for-each select="//title|//bullet|//normal">
     <xsl:if test="self::title">
     <section>
       <sectionTitle><xsl:value-of select="."/></sectionTitle>
       <xsl:for-each select="following::title|following::bullet|following::normal">
         <xsl:choose>
           <xsl:when test="self::normal">
	     <xsl:if test="preceding::title">
	       <text><xsl:value-of select="."/></text>
             </xsl:if>
           </xsl:when>
	   <xsl:when test="self::title">
	     <xsl:comment>Found next title, I would like to stop here</xsl:comment>
	     <xsl:for-each select="following::bullet|following::normal"/>
	   </xsl:when>
           <xsl:when test="preceding-sibling::*[1][self::bullet]"/>
           <xsl:otherwise><!--at the first of a group of siblings-->
             <ul><!--"walk" along all sibling bullets for list items-->
               <xsl:apply-templates select="." mode="sibling-bullets"/>
             </ul>
           </xsl:otherwise>
         </xsl:choose>
       </xsl:for-each>
     </section>
     </xsl:if>
    </xsl:for-each>
  </result>
</xsl:template>

<xsl:template match="title">
  <section>
    <sectionTitle><xsl:value-of select="."/></sectionTitle>
     <xsl:apply-templates/>
  </section>
</xsl:template>

<xsl:template match="bullet">
   <xsl:choose>
         <!--when there is an immediate sibling of the same name,
             then assume this node has already been addressed by
             the first of the contiguous siblings-->
     <xsl:when test="preceding-sibling::*[1][self::bullet]"/>
     <xsl:otherwise><!--at the first of a group of siblings-->
       <ul><!--"walk" along all sibling bullets for list items-->
         <xsl:apply-templates select="." mode="sibling-bullets"/>
       </ul>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<!--place each of a group of adjacent siblings-->
<xsl:template match="bullet" mode="sibling-bullets">
   <li><xsl:apply-templates/></li> <!--put out this one-->
                                   <!--go to next one-->
   <xsl:apply-templates
             select="following-sibling::*[1][self::bullet]"
             mode="sibling-bullets"/>
</xsl:template>

<xsl:template match="normal">   <!--other stuff-->
   <text><xsl:apply-templates/></text>
</xsl:template>

</xsl:stylesheet>

here is my output

<result>
  <section>
    <sectionTitle>Here is my first title!</sectionTitle>
    <ul>
      <li>first group first bullet</li>
      <li>first group second bullet</li>
    </ul>
    <text>first group first normal</text>
    <ul>
      <li>first group third bullet</li>
    </ul>
    <!--Found next title, I would like to stop here-->
    <ul>
      <li>second group first bullet</li>
    </ul>
    <text>second group first normal</text>
    <ul>
      <li>second group second bullet</li>
      <li>second group third bullet</li>
    </ul>
  </section>
  <section>
    <sectionTitle>Here is my second title!</sectionTitle>
    <ul>
      <li>second group first bullet</li>
    </ul>
    <text>second group first normal</text>
    <ul>
      <li>second group second bullet</li>
      <li>second group third bullet</li>
    </ul>
  </section>
</result>

So this details my problems with xslt.

- earl


Earl Bingham
1568 Plateau Avenue
Los Altos Hills, CA 94024
H: (650) 559-1738
C: (408) 806-6642

____________________________________________________
get your permanent, free email at http://www.flashemail.com


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


Current Thread