Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare current value with previous parent node in xsl 1

Status
Not open for further replies.

ratjetoes

Programmer
May 24, 2002
30
NL
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:eek:therwise>
<xsl:value-of select="."/>
</xsl:eek:therwise>
</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.
 
This is a slightly verbose, hence clearer, version.
[tt]
<xsl:choose>
<xsl:when test="parent::*/preceding-sibling::Row/Column[position()]/text()=current()/text()">
<xsl:text>..</xsl:text>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="."/>
</xsl:eek:therwise>
</xsl:choose>
[/tt]
 
Further note
Upon re-read what I posted, I would prefer not referencing Row explicitly, making it less contingent to specific tag name design, and in particular, I don't think there is any preceding-sibling other than Row, hence, this may be a better line to replace the corresponding one.
[tt] <xsl:when test="parent::*/preceding-sibling::[red]*[/red]/Column[position()]/text()=current()/text()">
[/tt]
 
tnx for the answer!

i made a small adjustment for your answer, since i only needed to check for the previous value in the previous record, not all previous records.

tnx again!
 
>i made a small adjustment for your answer, since i only needed to check for the previous value in the previous record, not all previous records.
You're quite right, that was logically also my understanding of the question at the start. But when I tried to put down the axis etc, I overlooked that detail. This will be the amendment for it. Thanks for noting it.
[tt] <xsl:when test="parent::*/preceding-sibling::*[red][1][/red]/Column[position()]/text()=current()/text()">[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top