xsl-list
[Top] [All Lists]

Re: [xsl] Displaying Unique attribute value

2008-10-29 10:12:53
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::*[(_at_)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="*[(_at_)page-num]">
    <!-- if it has a new page number ... -->
    <xsl:if
      test="normalize-space( @page-num ) != normalize-space( 
preceding::*[(_at_)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>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--