Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Use variables to get unique nodes

From: KemperR@--.---.-- (---- ------)
To: NULL
Date: 10/1/2004 8:05:00 AM
Dear Experts,

I got stuck with the following problem and need your help.

What I wnat to do is to get a set of distinct nodes.
Before the distinct I have selected the multiple occourences already
sucsessfully. However , the rest does not work as expected.

Hope someone can help on that.
Rolf

############################### DATA ################################

My XML DATA:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
	<TEST>
		<Pin  PinName="A" />
		<Pin  PinName="B" />
		<Pin  PinName="B" />
		<Pin  PinName="C" />
		<Pin  PinName="X" />
	</TEST>
	<TEST>
		<Pin  PinName="A" />
		<Pin  PinName="D" />
		<Pin  PinName="C" />	
		<Pin  PinName="X" />
		<Pin  PinName="A" />
	</TEST>
</Root>


My Test XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<xsl:output method="text"/>
	<xsl:variable name="NewLine" select="'&#x0d;&#x0a;'"/>
	
	<xsl:variable name="TestNodes" select="Root/TEST"/>
	<xsl:variable name="MultiplePins"  select="$TestNodes/Pin[@PinName =
preceding::Pin/@PinName]"/>
	<xsl:variable name="UniqueMultiplePins" 
select="$MultiplePins[@PinName != preceding::*/@PinName]"/>

    <xsl:template match="/">
        <xsl:value-of select="concat('all pins of all test nodes ==>
OK ',$NewLine)"/>
		<xsl:for-each select="$TestNodes/Pin">
			<xsl:value-of select="concat(@PinName,$NewLine)"/>
		</xsl:for-each>	
		<xsl:value-of select="$NewLine"/>
		
		<xsl:value-of select="concat('multiple pins  ==> OK ',$NewLine)"/>
		<xsl:for-each select="$MultiplePins">
			<xsl:value-of select="concat(@PinName,$NewLine)"/>
		</xsl:for-each>
		<xsl:value-of select="$NewLine"/>
		
		<xsl:value-of select="concat('unique pins ==> NOT GOOD !!
',$NewLine)"/>
		<xsl:for-each select="$UniqueMultiplePins">
			<xsl:value-of select="concat(@PinName,$NewLine)"/>
		</xsl:for-each>
		
    </xsl:template>
   
</xsl:stylesheet>

My results (gained by XMLSpy debug mode):

all pins of all test nodes ==> OK 
A
B
B
C
X
A
D
C
X
A

multiple pins  ==> OK 
B
A
C
X
A

unique pins ==> NOT GOOD !! 
B
A
C
X
A

( I expected B A C X )
#################### End #################################


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent