Wrox Programmer Forums
|
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 17th, 2006, 07:42 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default XPATH

Hi,

Please, could you help me to understand what the following xpath expressions really mean? I think I am misunderstanding what they mean.

1 - <xsl:if test="parent::* and count(parent::*/*)>1">

(*) Does 'parent::*' mean go to the parent element and down to the first child of the parent element?

Or does it mean go to parent and get all the children of the parent element?

(*/*) What about 'parent::*/*' Does it mean go to parent and then down to the first child and then to its children and check if count is greater than one?

2 - <xsl:if test="*">

Does '*' mean check if the current element has a child node?


Thanks for you help

Cheers,

CPall
 
Old November 17th, 2006, 09:27 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

1 - <xsl:if test="parent::* and count(parent::*/*)>1">

(*) Does 'parent::*' mean go to the parent element and down to the first child of the parent element?

No. It means select the parent element, whatever its name.

parent::*/* is short for parent::*/child::*, which selects the parent element whatever its name, and then selects all the child elements (of the parent), again regardless of their element name.

2 - <xsl:if test="*">

Does '*' mean check if the current element has a child node?

That's the effect, but only indirectly. * is short for child::*, which selects all the child elements of the context node. Used in a boolean context, a node-set is true if it is non-empty. So you are testing whether the node-set consisting of all the child elements is non-empty.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 19th, 2006, 06:39 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi Michael,

Thanks a lot for you explanation. It is a lot clearer to me now.

There is only one thing I am still not sure about as follows:

if I have a xml document that looks like that:

<companystaff name="TEST" email="" >
    <companystaff department="DEV" name="" email="">
      <companystaff name="Web" email="">
        <companystaff name="Controls" email="">
          <companystaff name="User" email="" />
          <companystaff name="Server" email="" />
        </companystaff>
      </companystaff>
    </companystaff>
    <companystaff department="WebModules" name="" email="">
</companystaff>

'
parent::*/* is short for parent::*/child::*, which selects the parent element whatever its name, and then selects all the child elements (of the parent), again regardless of their element name.
'
If my current node is the first child of the document element -

<companystaff department="DEV" name="" email="">

then this expression parent::*/* will take me to the parent node (document element) and select
these <companystaff department="DEV" name="" email=""> and <companystaff department="WebModules" name="" email="">

Is that right?

What about if I want to select all the children and grandchildren and so on of the parent? I thought this -parent::*/* - would select all the children and grandchildren. Therefore, I was wrong and thank you for your help.

Cheers

CPall
 
Old November 19th, 2006, 07:46 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

To select all the descendants of the parent, do parent::*/descendant::* (or ..//* in the abbreviated form)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 19th, 2006, 07:50 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Thanks again Michael.

This helped me a lot





Similar Threads
Thread Thread Starter Forum Replies Last Post
XPATH pallone XSLT 4 March 3rd, 2008 10:58 AM
Xpath help please rishid XML 1 February 28th, 2007 03:23 AM
XPath help migake XSLT 2 April 21st, 2006 10:49 AM
Xpath Ma7T XSLT 2 August 16th, 2005 07:54 AM
XPath rupen XML 2 April 19th, 2005 09:43 AM





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