p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   How to detect the level of an element (http://p2p.wrox.com/showthread.php?t=67556)

aliov_85 April 20th, 2008 01:04 PM

How to detect the level of an element
 
HI

I would like to detect the level of an element in according to his root.
Quote:

quote:
  <Issue issueID="" composer="" date="">
    <Proposition composer="" date="" level="1" actname="proposition">
      <Agreement composer="" date="" level="2"></Agreement>
    </Proposition>
  </Issue>
Suppose that I want to output all elements nested just in the "Issue" element and not in it's sub element and I also don't know their name(Proposition is an example and I have to be able to output even if it changes).

How can I output an element considering the only information I have that element is it's level(from the root), by the way of an attribute("level").

Thanks in advance

Ali


mhkay April 20th, 2008 04:43 PM

If Issue is the current element then you can process all its children, regardless of their name, using <xsl:apply-templates select="child::node()"/>. In fact child::node() abbreviates to node(), and this is the default for apply-templates anyway.

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

mhkay April 20th, 2008 04:47 PM

I fear my response probably wasn't very helpful, but it's hard to know where you are having problems. I think it would help if you showed us the output you want to generate, and the code you have written so far.

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

Alain COUTHURES April 21st, 2008 01:11 AM

Using XPath you can locate an element according to its level attribute with an expression such as this :
Code:

descendant::*[@level=$mylevel]


All times are GMT -4. The time now is 06:19 PM.

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