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 2nd, 2012, 01:58 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default Problem Getting to Nodes

Hello.

I have the following XML file.
Code:
<doc>
    <EOB>
        <DETAIL>
            <DETAILLINE>
                <RCDATA>
                    <RCDATALINE>
                        <TRC>AAAAAAAAA1</TRC>
                    </RCDATALINE>
                    <RCDATALINE>
                        <TRC/>
                    </RCDATALINE>
                </RCDATA>
                <CRCDATA>
                    <CRCDATALINE>
                        <CRCFUNCTION>900</CRCFUNCTION>
                    </CRCDATALINE>
                    <CRCDATALINE>
                        <CRCFUNCTION/>
                    </CRCDATALINE>
                </CRCDATA>
            </DETAILLINE>
            <DETAILLINE>
                <RCDATA>
                    <RCDATALINE>
                        <TRC>WWWWWWWW1</TRC>
                    </RCDATALINE>
                    <RCDATALINE>
                        <TRC/>
                    </RCDATALINE>
                </RCDATA>
                <CRCDATA>
                    <CRCDATALINE>
                        <CRCFUNCTION>900</CRCFUNCTION>
                    </CRCDATALINE>
                    <CRCDATALINE>
                        <CRCFUNCTION/>
                    </CRCDATALINE>
                </CRCDATA>
            </DETAILLINE>
        </DETAIL>
    </EOB>
</doc>
I want to execute a template only if any occurrence of <TRC> has some text and any occurrence of <CRCFUNCTION> is not = '900'.

I tried the following code but the template is executed even though both the
<CRCFUNCTION> in both the <DETAILLINE> is '900'.

Code:
        <xsl:if test="/doc/EOB/DETAIL/DETAILLINE/RCDATA/RCDATALINE/TRC/descendant-or-self::*[.!=''] and /doc/EOB/DETAIL/DETAILLINE/CRCDATA/CRCDATALINE/CRCFUNCTION/descendant-or-self::*[.!='900']">
Any help will be greatly appreciated!

Thanks,
Rita
 
Old August 2nd, 2012, 04:54 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Well, I finally figured out my problem. Using "<xsl:if test="/doc/EOB/DETAIL/DETAILLINE/CRCDATA/CRCDATALINE/CRCFUNCTION!='900"> didn't work because there was a CRCFUNCTION that was = '' which satisfied the if condition.

So now I need to determine if the CRCFUNCTION is not = '900' and not = ''.
Can somebody help me with that? I tried using position() but could not get it to work.

Thanks!
 
Old August 3rd, 2012, 12:01 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Generally, steer well clear of the "!=" operator when the operands are possibly empty or possibly multiple values. Use not(A = B) instead. So here you want not(. = ('900', ''))
__________________
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:
ritagr (August 3rd, 2012)
 
Old August 3rd, 2012, 12:46 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Wow! Thank you so much.
I knew there has to be a simple answer :-)





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem accessing nodes using document() and id() siris phi XSLT 3 April 12th, 2007 11:05 PM
Problem Copying Nodes tclotworthy XSLT 14 February 13th, 2007 01:13 PM
Nodes ....'For Each' problem. Neal XSLT 3 February 13th, 2006 08:57 AM
Problem copying XML nodes francislang XSLT 9 October 21st, 2005 10:37 AM
reorder nodes problem pompluck XSLT 4 November 5th, 2003 09:02 AM





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