[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Creating Hierarchy

Subject: Re: Creating Hierarchy
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 17 Oct 2008 11:52:34 -0400
Re:  Creating Hierarchy
At 09:18 AM 10/17/2008, Ken wrote:
At 2008-10-17 13:47 +0100, Rowan Sylvester-Bradley wrote:
You'll find a description of an XSLT 2.0 stylesheet that does this (and some
other things besides) at

http://www.idealliance.org/proceedings/xml04/papers/111/mhk-paper.html

Michael Kay
http://www.saxonica.com/

Thanks to Michael and Ken for your replies. I've now got it more or less working using xsl:for-each-group. However, I've got another problem that I can't quite work out. Each of the main elements in the result file needs to have a unique ID attribute.

An ID attribute value must be a name token, so your "1","2",... won't be correct. But you could use something like "N1","N2",...

Of course, the OP hasn't actually said his attributes named "id" need to validate as type ID. (Not that this isn't good advice in general, in case one ever wanted to do that.)


I.e. the id attributes just keep incrementing regardless of the hierarchy.

How do I generate the values of these id attributes?

Assuming the current node is <node>, then <xsl:number/> can be used without attributes to count the current node amongst its siblings in the source tree:


<xsl:attribute name="id">N<xsl:number/></xsl:attribute>

In more complex cases -- maybe there wasn't a one-to-one relation between nodes in the source and the result -- the simplest method would probably be to perform a second pass for the ID labeling.


It's funny how xsl:number has come up a lot lately. One of those things that happens from time to time, I guess.

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.