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 November 10th, 2007, 04:14 PM
Registered User
 
Join Date: Nov 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Having issues with a test condition...

Greetings,

I'm having problems with some logic and I was curious if someone could straighten me out... What I'm trying to do is run a check to see if extra NTP servers are configured other than my two primary servers. 1.1.1.1 is the rogue device in this case. If I see that there are NTP servers configured over and above my standard servers I generate an error message. Here is the XML source that I'm running my XSLT against:

    <configuration junos:changed-seconds="1194721954" junos:changed-localtime="2007-11-10 13:12:34 CST">
        <system>
            <ntp>
                <junos:comment>/* NTP Servers */</junos:comment>
                <boot-server>10.60.49.21</boot-server>
                <server>
                    <name>10.60.49.21</name>
                    <prefer/>
                </server>
                <server>
                    <name>10.60.48.248</name>
                </server>
                <server>
                    <name>1.1.1.1</name>
                </server>
                <source-address>10.87.11.220</source-address>
            </ntp>
        </system>
    </configuration>

Here is the logic that I know is jacked up in my XSLT:

<xsl:for-each select="system/ntp/server">
   <xsl:variable name="server-name" select='name'/>
   <xsl:if test="$server-name!='10.60.48.248' or $server-name!='10.60.49.21'">

   </xsl:if>
</xsl:for-each>

You can see what I'm trying to test against is if the $server-name variable does not equal either of my valid ntp servers then I call my error. The problem is that the way that I have my logic laid out in the for loop it is always going to come back true even if everything is correct. Any ideas for restructuring my logic so that I can achieve the desired behavior? BTW, I'm calling a template in the full script to reference everything at /configuration. That is why it isn't referenced in my for loop.

Thanks,

Randy


 
Old November 10th, 2007, 09:32 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

When X is a node-set, X!=b is true if at least one X is not equal to b. You want not(X=b), which is true if there is no X that is equal to b.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 10th, 2007, 10:00 PM
Registered User
 
Join Date: Nov 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael,

Thank you very much for the quick response. Are you saying I should try something like:

  <xsl:if test="not($server-name='10.60.48.248' or '10.60.49.21'">

I'm pretty confident that I had tried that, but I think my syntax was screwed up. Am I missing something obvious? I can make my XSLT work fine if I'm only testing against one "server", when I test against two that is when the "operator-malfunction" ;) errors start manifesting themselves.


 
Old November 11th, 2007, 04:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

No, XPath doesn't allow (A = B or C). You can write this as (A=B or A=C), or in XPath 2.0 you can write it as (A=(B, C)).

Also, not(X or Y) can be written as (not(X) and not(Y)).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
connection string issues, web.config file issues kaliaparijat ASP.NET 2.0 Professional 1 June 12th, 2008 08:07 AM
Usage of '*' in test condition of <xsl:when> vikkiefd XSLT 5 March 12th, 2008 10:31 PM
Problem with variable in test condition bartnowa XSLT 3 December 20th, 2007 07:31 AM
if then else condition mateenmohd Classic ASP Basics 0 April 16th, 2005 07:08 AM
Condition mateenmohd SQL Server 2000 6 May 6th, 2004 03:49 AM





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