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 15th, 2008, 10:56 AM
Registered User
Join Date: Nov 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Finding nested elements XSLT 1?

Can anyone tell me if there is a way to find elements that contain child element with the same local-name() nested some number of levels deep?

For example, let's say I want to create a stylesheet template that matches on any element nested 5 levels deep where its 4 ancestors have the exact same local-name(). Here's an example of what I'd like to be able to detect:


but not


I can't seen to figure out how to write an XPath expression that matches an element whose parent's local-name() is the same as its local-name().

Any assistance greatly appreciated.

Old November 15th, 2008, 11:02 AM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

<xsl:template match="bar/bar/bar/bar/bar">

if you know the name. If you don't know the name,

match="*[name(..)=name(current()) and name(../..)=name(current()) and name(../../..)=name(current()) and so on]"

Michael Kay
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Old November 15th, 2008, 02:45 PM
Registered User
Join Date: Nov 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Hi Michael,
Thank you very much! I'm in the second scenario where I don't know the name of the element, I simply want to do some processing when I see any element of the same name nested 'N' levels deep.

I was originally trying to do something along the lines of:

match="*[local-name() = ancestor::local-name()]/*[local-name() = ancestor::local-name()]" (etc.) and was apparently confusing both the XSLT processor and myself. :-)

Thanks again!

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem nested elements Geierwally XSLT 7 May 9th, 2007 07:27 AM
path for nested elements rjonk XSLT 7 November 20th, 2006 05:43 AM
sorting nested elements again stekker XSLT 1 June 5th, 2006 03:38 AM
sorting nested elements stekker XSLT 5 June 5th, 2006 01:19 AM
Dynamically Finding Elements in XSL tclancy XSLT 2 March 1st, 2006 03:25 PM

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