This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

grouping every three nodes?


Hello,

I've searched the FAQ and tutorials, and I can't seem to find an answer to
this problem.  Actually, I don't think it's possible, but I was hoping
someone could lend some advise.

demo xml file:
<group>
 <item></item>
 <item></item>
 <item></item>
 <item></item>
 <item></item>
</group>

I would love to be able to do this in XSL:

<xsl:template match="group">
	"grab every three item tags and send to named template"
</xsl:template>

<xsl:template name="group-of-three">
 <td>
  <ul>
  <xsl:for-each select="item">
   <li><xsl:value-of select="."/></li>
  </xsl:for-each>
  </ul>
 </td>
</xsl:template>

I'm not sure how to grab every three nodes from a nodeset.  I'm trying to
build a table for every three items in a list.  because of the fact that
XSL outputs trees, I'm having a hard time.  The following would work,
except it's not valid XML

<!-- won't work -->
<xsl:template match="group">
 <table>
  <tr>
   <xsl:for-each select="item">
    <xsl:if test="(position() mod 3) = 0">
     <td>
     <ul>
    </xsl:if
    <xsl:value-of select="."/>
    <xsl:if test="(position() mod 4) = 0">
     </ul>
     </td>
    </xsl:if>
   </xsl:for-each>
  </tr>
 </table>
</xsl:template>

Is there anything that will help me break up a nodeset into a group of
three?  I've solved my problem by using the hack disable-output-encoding,
but I'd like to stay away from that.

Thanks for any help or pointers you can give me,
Seth


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]