Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 2nd, 2007, 07:50 AM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default getting the parent

I am in one node i want to get it's parent ....and the parent of this parent

for example
<root>
   <node1>
      <child1>
            <mynode>
     </child1>
   </node1>
</root>

i'm in mynode....now first i want to get child1..then i will do something and from child1 i want to go node1....

but this going will by dynamically nut specifying the path with node name...like node1/child1 directly..
how to do that?


Reply With Quote
  #2 (permalink)  
Old March 2nd, 2007, 08:27 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

.. fetches the parent.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old March 2nd, 2007, 08:38 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

Asking this question on a forum seems to be a very inefficient way of getting basic information. What reference book are you using, and isn't the information in the index under "parent"?

The expression ".." returns the parent of the context node.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old March 3rd, 2007, 12:52 AM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<xsl:template name = "checkPosition1" match ="/node()">
    <xsl:template match ="/node()">
    <xsl:choose>
            <xsl:when test="position()=last()">
                <img class="hiericon" src="images/blank.png"/>
            </xsl:when>
            <xsl:otherwise>
                <img class="hiericon" src="images/I.png"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:template>


actulally i want to check if the parent is the last position if so i want to put my image...to do that i have written that template that will check 2nd level parent of the corrent node..

and my node structure is like that...
<parent1>
<parent2>
<parent3>
     <ch1>
          <nod1>
          <nod2>
     <ch2>
          <node1>
          <node2>

here parent3 is in the last position and from node1 or node2 i want to check parent3 is in the last or not if in last then i will put blank image and if not then i will put I image..

but it's not working..i'have tried with '..' also but giving some syntax error...i think my template stucture is worng..xslt 1.0 i'm using

Reply With Quote
  #5 (permalink)  
Old March 3rd, 2007, 01:27 AM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have tried like this also..

<xsl:template name = "checkPosition1" match ="/node()">
 <xsl:for-each select="..">
    <xsl:for-each select="..">
    <xsl:choose>
            <xsl:when test="position()=last()">
                <img class="hiericon" src="images/blank.png"/>
                            </xsl:when>
            <xsl:otherwise>
                <img class="hiericon" src="images/I.png"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
    </xsl:for-each>
</xsl:template>

here i can get the 2nd level aprent but it always satisfying the position()=last()

i'm not getting why ..

Reply With Quote
  #6 (permalink)  
Old March 3rd, 2007, 04:31 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

You wrote:

 <xsl:template name = "checkPosition1" match ="/node()">
    <xsl:template match ="/node()">

You can't have one template inside another - I don't know what you would expect it to mean. match="/node()" matches any node that is a direct child of the document root - I don't know what you expected that to achieve either.

The construct

<xsl:when test="position()=last()">

does not test the position of a node in the source tree, it tests its position in the current sequence of nodes being processed. Sometimes that's the same thing, but not in this case, because you aren't processing nodes in tree order. In particular when you do it within

<xsl:for-each select="..">

the current node list contains a single node (the parent), so position() and last() are both equal to 1.

>i want to check if the parent is the last position

that's test="not(../following-sibling::*)"



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #7 (permalink)  
Old March 3rd, 2007, 04:58 AM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thnx for reply..so the problem with my template stucture..can pls help me with the syntax how to get the 2nd level parent position
Reply With Quote
  #8 (permalink)  
Old March 3rd, 2007, 10:25 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

>but this going will by dynamically nut specifying the path with node name...like node1/child1 directly.. how to do that?

I don't understand your question. Please try to express yourself more clearly. In fact, please read your sentences before hitting send, and ask yourself whether they make sense.

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
parent/ancestor nmnm XSLT 1 April 24th, 2007 05:25 AM
No control over parent paths mat41 Classic ASP Professional 16 December 19th, 2006 05:15 PM
parent child presentation db96s1 Beginning PHP 0 February 7th, 2006 06:19 PM
parent::* debo_sbg XSLT 5 April 1st, 2005 02:45 PM
Check for Parent Window jae Javascript How-To 1 June 8th, 2004 02:01 PM



All times are GMT -4. The time now is 05:25 AM.


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