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 August 17th, 2007, 03:45 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default finding if a node value doesn't exist

I'm using Saxon 8.

I must be over thinking this and I've reach a mental block.

My application is to compare two nearly identical XML files (or collections of XML files) and identify specific differences.

I might have a node somewhere in one file with a value of "XYZZY" that may not exist in the other file.

It's certainly easy enough to find if it does exist
Code:
    <xsl:template name="CmdCommon">
        <xsl:param name="source"></xsl:param>
        <xsl:param name="target"></xsl:param>
        <xsl:for-each select="$source//TL1CommandNameHeading/Head">
            <xsl:if test=". = $target//TL1CommandNameHeading/Head">
                <xsl:value-of select="."></xsl:value-of>
                <xsl:text>#x0A;</xsl:text>
            </xsl:if>            
        </xsl:for-each>        
    </xsl:template>
but finding if it doesn't exist is proving a bit tougher.

My initial choice is returning nothing

Code:
    <xsl:template name="CmdDifference">
        <xsl:param name="source"></xsl:param>
        <xsl:param name="target"></xsl:param>
        <xsl:for-each select="$source//TL1CommandNameHeading/Head">
            <xsl:if test="empty(. = $target//TL1CommandNameHeading/Head)">
                <xsl:value-of select="."></xsl:value-of>
                <xsl:text>#x0A;</xsl:text>
            </xsl:if>            
        </xsl:for-each>        
    </xsl:template>
How do I determine if a specific value for a node in one document doesn't exist in another?

Thanks!

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

Michael Hare
__________________
------------------------
Keep Moving Forward

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

Michael Hare
 
Old August 17th, 2007, 03:52 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

That helped.. I just needed to clear my mind.

I replaced empty() with not() and wha-la!

Thanks!

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

Michael Hare
 
Old August 18th, 2007, 09:56 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Use

<xsl:if test="not(. = $target//TL1CommandNameHeading/Head)">


empty() tests whether a set is empty, applying it to a boolean value will always return true because neither true() nor false() is an empty set.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 19th, 2007, 05:42 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Yeah, I think I had a Friday afternoon brain freeze..
The answer came to me almost as soon I had finished posting the question.
I'm not sure why I ever though empty() was going to do it for me..

Thanks Michael!

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

Michael Hare





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
Finding parent node Chamkaur XSLT 4 August 9th, 2006 06:26 AM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM
Problem regarding finding the node in xslt. rohitjain13 XSLT 1 October 6th, 2005 03:26 AM
finding the most recent node... clayman58 XSLT 5 July 21st, 2005 01:41 PM





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