Re: [xsl] Displaying Unique attribute value

Subject: Re: [xsl] Displaying Unique attribute value
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Wed, 29 Oct 2008 10:12:15 -0400
I think maybe I don't understand the desired input & output quite
correctly here. I would have thought something like 

   <xsl:if
        test=" normalize-space( @page-num )
               !=
               normalize-space( preceding::*[@page-num][1]/@page-num )">

would do the trick. Is there something wrong with this approach that
I'm missing? Perhaps the grouping approach suggested is significantly
more efficient?


> > Each and every element is having page-num attribute. Suppose if
> > 10 elements are there in the first page, all ten tags will have
> > page-num="1". the 11th element will have page-num="2". I want to
> > display page-num value in the browser where it is changing from
> > the previous value. In other words I have to display unique page
> > numbers when they occur first


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

  <!-- match root -->
  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>

  <!-- anything that isn't otherwise matched below just gets copied -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <!-- match any element that has a page-num= attribute -->
  <xsl:template match="*[@page-num]">
    <!-- if it has a new page number ... -->
    <xsl:if
      test="normalize-space( @page-num ) != normalize-space( preceding::*[@page-num][1]/@page-num )">
      <!-- display it (the page number) as a big heading ... -->
      <h1>Page: <xsl:value-of select="@page-num"/></h1>
    </xsl:if>
    <!-- and generate a copy of the element itself (including the page-num=) -->
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Current Thread