Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 27th, 2011, 03:30 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default Find item in one result in another result

First, let me say that many people here, at work, have told me XSLT is the completely wrong language to be working in. I should be using JAVA or PERL or EXPECT, etc..

Since all my data sits squarely in the XML space, I believe there is no better language than XSLT to be doing my work.

Now, I develop using Saxon 9 on a Windows 7 box, but my code also runs in production on Solaris.

I have two temporary results, they are structured the same:
Code:
<base>
   <entity>A</entity>
   <entity>B</entity>
   <entity>C</entity>
</base>

and

<base>
   <entity>X</entity>
   <entity>Y</entity>
   <entity>Z</entity>
</base>
My quest is to determine if any of the entities in the first result exist in the second result. If it does, I would like for the function/template to give me the value-of the entity that matched. If none matched, then I'd like an empty string. I don't care if more than one matches, I just need to know if at least one matches.


I believe there to a a simple solution to this problem, one that I completely passed over as I jumped to the more difficult solutions.

Please, help!

Thanks,

- mike
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old October 27th, 2011, 03:58 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

So many good things to learn about XPath.. for example.. the 'some' 'satisfies' construct.

Code:
<xsl:sequence select="some $i in base1//entity satisfies exists(base2//entity[. eq $i])"></xsl:sequence>
Seems to do exactly what I was looking for.
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old October 27th, 2011, 06:04 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Actually it's even simpler:

Code:
base1/entity = base2/entity
returns true if any node in base1/entity has the same value as some node in base2/entity
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
mphare (October 27th, 2011)
 
Old October 28th, 2011, 10:51 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

This is where my lack of understanding the XSLT processing model really shines.

I would have looked at base1/entity = base2/entity as meaning the two are only equal if the entire sequence: base1/entity was equal to the entire sequence: base2/entity.

As I said.. lots to learn in XPath.

Thanks again, Michael. Have a nice weekend!
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare





Similar Threads
Thread Thread Starter Forum Replies Last Post
Result of Transformation PKHG BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 4 August 6th, 2008 10:57 AM
GridView and SQL More than one result = one result DarkForce ASP.NET 2.0 Basics 0 July 20th, 2007 04:29 AM
How many Result? Mantis PHP Databases 1 April 15th, 2005 03:37 PM
Result set jemacc SQL Server 2000 0 December 19th, 2003 07:26 PM
Find Out First Item of each item Group Jane SQL Language 1 November 22nd, 2003 12:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.