[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Navigating XML Using Attributes
James,
You can do it without, but keys were invented just for this purpose. Look them up: they're described in the XSLT spec or in any decent book or web resource on XSLT. In your case, the fact that you're using elements of exactly the same name and attribute name to refer to the target elements you want, you need to be careful in constructing your key. For example, if you declare a key like this: <xsl:key name="elements-by-id" match="*" use="@Id"/> And then, when processing the LevelA3 Id="111" element under the LevelA2 parent, you call <xsl:apply-templates select="key('elements-by-id', @Id)"/> you would process all elements with @Id="111", including the context node itself (thereby entering an infinite loop). But if you declare the key as <xsl:key name="top-level-by-id" match="Account/*" use="@Id"/> the same expression will return only the <LevelA3 Id="111"> child of <Account> -- since the other one (the context node) doesn't match the pattern used in the key declaration. I hope this is enough to get you moving. You can either declare one key for all your elements, or separate keys for your separate types. Either way they can be chained as you describe. Good luck, Wendell At 04:42 PM 2/11/2003, you wrote: I have an XML document that was dumped from a database. Instead of the elements being nested in an appropriate, well-formed XML fashion, they are associated with ID attributes. The following XML is a generalized sample with Account being the root element: ====================================================================== 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 ====================================================================== XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|