Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
Reply With Quote
  #2 (permalink)  
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>
Reply With Quote
  #3 (permalink)  
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!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:46 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.