Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2008, 10:55 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compare current value with previous parent node

hi,

i have a xml document like this:
<Row>
  <Column>Value A</Column>
  <Column>Value B</Column>
</Row>
<Row>
  <Column>Value C</Column>
  <Column>Value B</Column>
</Row>

Now i would like to print the rows as:
 Value A Value B
 Value C ..

If the current value of the column is the same as the value of the column of the previous parent node (Row) then don't repeat the value but print .. or blank.

how can i achieve this in xslt?

i have something similar as:
<xsl:template name="Columns">
  <xsl:for-each select="Column">
    <fo:table-cell>
    <fo:block>
          <xsl:choose>
            <xsl:when test="parent::*/previus-sibling::Column = Column">
               ..
            </xsl:when>
            <xsl:otherwise>
          <xsl:value-of select="."/>
            </xsl:otherwise>
          </xsl:when>
    </fo:block>
    </fo:table-cell>
  </xsl:for-each>
</xsl:template>

i was wondering what the right code would be for the test property of xsl:when.

it needs to compare for the current column the value of the current column in the current row with the value of the current column in the previous row.

the template Columns is being called from within a for-each loop of the rows.

any help appreciated.

t.i.a.,
erik.
 
Old July 16th, 2008, 02:08 PM
Authorized User
 
Join Date: May 2008
Location: Moscow, , Russia.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
<xsl:template name="Columns">
  <xsl:for-each select="Column">
   <xsl:variable name="pos" select="position()"/>
    <fo:table-cell>
    <fo:block>
          <xsl:choose>
            <xsl:when test="parent::Row/preceding-sibling::Row/Column[$pos]=current()">
               ..
            </xsl:when>
            <xsl:otherwise>
          <xsl:value-of select="."/>
            </xsl:otherwise>
          </xsl:choose>
    </fo:block>
    </fo:table-cell>
  </xsl:for-each>
</xsl:template>
 
Old July 17th, 2008, 06:15 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

tnx for your answer!

i made a slight adjustment since i only needed to check for the previous record and not all previous records.

parent::Row/preceding-sibling::Row[1]/Column[$pos]=current()

tnx again!





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to store the previous node value Neha XSLT 3 July 23rd, 2008 05:42 AM
Compare previous value of DropDownList on Postback densom ASP.NET 2.0 Basics 0 October 23rd, 2006 02:10 PM
how to check the current value and the previous va tllcll BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 October 24th, 2005 02:25 PM
xpath: position parent of current node orion83 XSLT 1 September 5th, 2005 07:20 AM
How do I get Data from the previous node? runeteacher XSLT 5 October 13th, 2004 03:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.