[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Displaying Unique attribute value

Subject: Re: Displaying Unique attribute value
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Wed, 29 Oct 2008 10:12:15 -0400
Re:  Displaying Unique attribute value
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.