RE: [xsl] How do I compare all similar type nodes?

Subject: RE: [xsl] How do I compare all similar type nodes?
From: "McNally, David" <David.McNally@xxxxxxxxxx>
Date: Tue, 18 Dec 2001 12:13:04 -0500
A general question regarding this sort of handling of duplicates (I'm not
sure if it's in the faq, but I couldn't find an explicit mention) - am I
correct in thinking that if you have to worry about white space in the
values you're comparing, then you have to use keys?

Having to deal with things like this:

<foo>
	<bar>  123</bar>
	<bar>123</bar>
	<bar>456
</bar>
	<bar>123    </bar>
	<bar> 456</bar>
</foo>

with a desired output of 

123
456

doing something like

<xsl:for-each select="//bar">
	<xsl:if test="not(. = preceding-sibling::bar)"><xsl:text>
</xsl:text>
		<xsl:value-of select="normalize-space(.)"/>
	</xsl:if> 
</xsl:for-each>		

doesn't work because of the white space. This

not(normalize-space(.) = preceding-sibling::bar)

doesn't work because it only normalizes the context node, and this

not(normalize-space(. )= normalize-space(preceding-sibling::bar))

doesn't work because it's only comparing the context node and the first node
in doc order of the preceding-sibling access.

I have handled this by defining a key from the space normalized value of the
element plus the document position of its parent (to duplicate the
preceding-sibling behaviour) and then checking if the context node is the
first in its key group, but wondered if there was some combination of
preceding-sibling and normalize-space that would do what I mean.

I did find this in the archive - which seems to indicate that there isn't,
yet, any way to do this - 
http://www.biglist.com/lists/xsl-list/archives/199912/msg00336.html

Thanks,
David.
--
David McNally            Moody's Investors Service
Software Engineer        99 Church St, NY NY 10007 
David.McNally@xxxxxxxxxx            (212) 553-7475 



> -----Original Message-----
> From: Ahmad J Reeves [mailto:ahmad@xxxxxxxxxxxxxx]
> Sent: Tuesday, December 18, 2001 7:23 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] How do I compare all similar type nodes?
> 
> 
> Perfecto mundo
> 
> not far off in idea to my gobbldegook!
> 
> Cheers Chris
> 
> A.
> 
> Chris Bayes wrote:
> > 
> > Ok you want
> >         <xsl:for-each select="LOG/DIRECT/TARGET_CHARACTER_ID[not(. =
> > preceding::TARGET_CHARACTER_ID)]">
> >                 <xsl:sort select="." data-type="number"
> > order="ascending" />
> >                 <xsl:value-of select="position()" />. <xsl:value-of
> > select="." />
> >         </xsl:for-each>
> > 
> > Ciao Chris
> > 
> > XML/XSL Portal
> > http://www.bayes.co.uk/xml
> > 


---------------------------------------

The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission.  If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited.  If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments.  Thank you.

Every effort is made to keep our network free from viruses.  You should, however, review this e-mail message, as well as any attachment thereto, for viruses.  We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread