Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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:47 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Xpath expressions with attributes

Greetings,

I'm trying to write an Xpath expression to grab an IP address out of the following XML snippet:

<interface junos:group="re0">
   <name junos:group="re0">fxp0</name>
       <unit junos:group="re0">
            <name junos:group="re0">0</name>
            <family junos:group="re0">
                <inet junos:group="re0">
                   <address junos:group="re0">
                       <name junos:group="re0">10.87.11.220/24</name>
                           <master-only junos:group="re0"/>
                   </address>
                   <address junos:group="re0">
                       <name junos:group="re0">10.87.11.218/24</name>
                    </address>
                 </inet>
             </family>
          </unit>
       </interface>
    </interfaces>

I'm trying to grab the first IP address referenced which is 10.87.11.220/24. What should my Xpath expression look like for doing this? The junos:group="re0" is what is throwing me off...

Thanks,

Randy

 
Old November 10th, 2007, 09:35 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's easy enough to find the first <name> element that isn't equal to fxp0 or 0, but presumably those are not the only things that might occur before your first IP address. You need to specify how you are going to distinguish an element containing an IP address from all the other things that might be encountered; we can't do that from one example.

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

Michael,

Here is what I was trying to do, but it didn't seem to be working:

<xsl:var name="address-and-mask" select="//interface[@junos:group="re0"]/unit/family/inet/address[0]/name"/>

The thought being that address[0] would hit the first address element.

When I use my Xpath query tool I can see that:

//interface[@junos:group="re0"]/unit/family/inet/address

returns both of the address elements in this particular hierarchy that I'm interrogating. I need to figure out a way though to grab only the first IP address showing up and stick that in a variable.

I'm a newbie, so I hope my explanation is clear enough so that you can see what I'm trying to do.


 
Old November 11th, 2007, 04:51 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XPath indexing always starts at 1, not at zero.

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
Xpath - Selecting attributes bonekrusher XSLT 3 October 1st, 2008 12:27 PM
Get NodesList by Xpath with Attributes Filters AbrarNazeer XML 5 March 26th, 2008 01:02 AM
XSL Param with XPath expressions V4mp1r3 XSLT 7 June 1st, 2007 11:47 AM
.net XPath expressions arcuza XSLT 1 December 1st, 2005 09:33 AM
Regular Expressions in XPath sonicDace XML 0 February 12th, 2004 05:26 PM





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