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]

RE: breaking sorted material into subsections


Assuming XML looks something like this (@location left out because question
didn't pertain to parent's @location href):


<IndexEntryData>
  <index entry = "Ca">Index1</index>
  <index entry = "Aaaa">Index1</index>
  <index entry = "Az">Index1</index>
  <index entry = "Bz">Index1</index>
  <index entry = "Abb">Index1</index>
  <index entry = "Ba">Index1</index>
</IndexEntryData>

This works in MSXML3 and SAXON

<xsl:template match="/">                                
  <xsl:for-each select="//index">
    <xsl:sort select="@entry"/>

	<!-- if first character of @entry attrib of first preceding -->
	<!-- node is not equal to the context's @entry attrib -->
	<!-- it's a "break" on first character of @entry -->
	<!-- this works because we're already sorted by @entry -->

      <xsl:if test ="substring(preceding::*[1]/@entry, 1, 1) !=
substring(@entry, 1, 1)"> 
        <H2><xsl:value-of select="substring(@entry, 1, 1)" /></H2>
      </xsl:if>  

      <p>
        <a href="{../@location}">
          <xsl:value-of select="@entry"/>
        </a>
      </p>
  </xsl:for-each>
</xsl:template>


More of this type of thing in the FAQ

Don



> but what I want is something like:
> 
> <H2>A</H2>
> Aaaa
> Abb
> Az
> <H2>B</H2>
> Ba
> Bz
> <H2>C</H2>
> Ca
> 


 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]