comparing nodes

[nobr]How do you compare values of node that are not child?I want to loop through all the currentActivity while looping through CurrentActivity2. So you read the first currentActivity then loop through all the CurrentActivity2 nodes seeing if the TransDetailCount of currentActivity match any of the CurrentActivity2 TransDetailCount.

*** This is just a sample of the XML, I just need to know how to get all of the currentActivity2 nodes that map to the CurrentActivity based off the TransDetailCount

<OUTPUT>

<STATEMENT>

<CurrentActivity>

<TransDesc>First current </TransDesc>

<TransDetailCount>1</TransDetailCount>

</CurrentActivity>

<CurrentActivity>

<TransDesc>second current </TransDesc>

<TransDetailCount>2</TransDetailCount>

</CurrentActivity>

<CurrentActivity>

<TransDesc>Third current </TransDesc>

<TransDetailCount>3</TransDetailCount>

</CurrentActivity>

<CurrentActivity2>

<TransDesc> AC 1.1 </TransDesc>

<TransDetailCount>1</TransDetailCount>

</CurrentActivity2>

<CurrentActivity2>

<TransDesc>AC 1.2 </TransDesc>

<TransDetailCount>1</TransDetailCount>

</CurrentActivity2>

<CurrentActivity2>

<TransDesc>AC 2.1 </TransDesc>

<TransDetailCount>2</TransDetailCount>

</CurrentActivity2>

</STATEMENT>

</OUTPUT>

I抳e tried a few things and nothing works:

1.) This does not print any of the currentActivity2 nodes

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">

<xsl:variable name="outputData" select="/OUTPUT"/>

<xsl:variable name="statementData" select="$outputData/STATEMENT"/>

<xsl:for-each select="$statementData/CurrentActivity">

<tr>

<td><xsl:value-of select="TransDesc"/></td>

<td><xsl:value-of select="TransDetailCount"/></td><br/>

</tr>

<xsl:for-each select="$statementData/CurrentActivity2[TransDetailCount='$statementData/CurrentActivity/TransDetailCount']">

In

<td><xsl:value-of select="TransDesc"/></td><br/>

<td><xsl:value-of select="TransDetailCount"/></td><br/>

</xsl:for-each>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

2.) This just prints all of the currentActivity2 under each currentActivity

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">

<xsl:variable name="outputData" select="/OUTPUT"/>

<xsl:variable name="statementData" select="$outputData/STATEMENT"/>

<xsl:for-each select="$statementData/CurrentActivity">

<tr>

<td><xsl:value-of select="TransDesc"/></td>

<td><xsl:value-of select="TransDetailCount"/></td><br/>

</tr>

<xsl:for-each select="$statementData/CurrentActivity2">

<xsl:if test="TransDetailCount = $statementData/CurrentActivity/TransDetailCount">

In

<td><xsl:value-of select="TransDesc"/></td><br/>

<td><xsl:value-of select="TransDetailCount"/></td><br/>

</xsl:if>

</xsl:for-each>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

I could not get the compare or codepoint-equal xsl functions to work in the xsl:if. Any help would be a great help.[/nobr]

[4647 byte] By [deppe12a] at [2007-10-3 3:30:32]
# 1

> I just need to know how to get all of the currentActivity2 nodes that map to

> the CurrentActivity based off the TransDetailCount

I may be wrong, but I am going to try interpreting that as "I want to get a list of

CurrentActivity2 elements for which the text content of their TransDetailCount

child elements is equal to the text content of some TransDetailCount element

that is a child of one of its CurrentActivity siblings".

I believe the XPath expression for that is, assuming that the STATEMENT

element is the context node:

CurrentActivity2[TransDetailCount/text() = ../CurrentActivity/TransDetailCount/text()]

Or something a lot like that. You shouldn't have to write any loops, XPath is

already designed to work easily with node lists.

DrClapa at 2007-7-14 21:24:26 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

[nobr]Dr. Clap,

Thanks for the reply. The data can change, but I will always want to match the CurrentActivity2s that have the same TranDetailCount as the CurrentActivity. So it抯 a one to many relationships.I will want to print the TransDesc for the CurrentActivity and then print the TransDesc of the CurrentActivity2s under it.

So it would like something like this:

First current

AC 1.1

AC 1.2

If can抰 this and it did not work:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">

<xsl:variable name="outputData" select="/OUTPUT"/>

<xsl:variable name="statementData" select="/STATEMENT"/>

<xsl:for-each select="$statementData/CurrentActivity">

<tr>

<td><xsl:value-of select="TransDesc"/></td>

<td><xsl:value-of select="TransDetailCount"/></td><br/>

</tr>

<xsl:if test="CurrentActivity2[TransDetailCount/text() = ../CurrentActivity/TransDetailCount/text()]">

<td><xsl:value-of select="$statementData/CurrentActivity2/TransDesc"/></td><br/>

<td><xsl:value-of select="$statementData/CurrentActivity2/TransDetailCount"/></td><br/>

</xsl:if>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

The results for the code above are:

First current 1

second current 2

Third current 3

Which did not print the CurrentActivity2. Thanks for the helps![/nobr]

deppe12a at 2007-7-14 21:24:26 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Something like this?<xsl:for-each select="$statementData/CurrentActivity">

<xsl:value-of select="TransDesc"/>

<xsl:variable name="TDC" select="TransDetailCount/text()"/>

<xsl:for-each select="../CurrentActivity2[TransDetailCount/text() = $TDC]>

<xsl:value-of select="TransDesc"/>

</xsl:for-each>

</xsl:for-each>

DrClapa at 2007-7-14 21:24:26 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
Dr Clap, You are great! That worked wonderfully!!! Have a great weekend.Thanks,ibll
deppe12a at 2007-7-14 21:24:26 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...