[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Position of a Child
Thanks Wendell ! It works pretty fine, so I guess there's no need on refining the code for now :) Thanks again, Frank. -----Original Message----- From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx] Sent: viernes, 21 de septiembre de 2001 17:50 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: Position of a Child Hi Frank, At 03:27 PM 9/20/01, you wrote: >The problem with the solution you gave me is that this code is inside a >template (that matches the contextNode), and this template calls itself >recursively for a set of selected attributes. > >Basically what I'm doing is to filter the input xml to create an output >based in a list of Childs (that this particular node may have or not). >So going through every child for each one in the list and for each >contextNode would be a lot of processing. > >That is why I was using the select"*[name()=$NodeName]" to identify >the child without going through all of them. It sounds from this that the (count(*[name()=$NodeName]/preceding-sibling::*) + 1) solution would be best. This works on the assumptions that: - by "position" you mean to count among elements (i.e. there's no mixed-content type stuff with text nodes you have to worry about), and - you'll never have more than one of a given node, as in <ContextNode> <Child1/> <Child3/> <Child4/> <Child3/> <ContextNode> Here, if $NodeName were 'Child3' and you did (count(*[name()=$NodeName]/preceding-sibling::*) + 1) you'd get 5, which isn't what you want. If you know you'll never have more than one Child3, on <ContextNode> <Child1/> <Child4/> <Child3/> <ContextNode> you'd get 3, which is correct. position() is less useful to you because you have to change context and establish the correct node list in order to be able to use it -- and from what you describe, this could be too busy. (You still might try the other solution though: you might be surprised.) To get deeper into this, if the count() solution isn't good enough, maybe you could try explaining what your recursive template call on ContextNode is actually doing: maybe there's a more efficient way to get at the problem this is solving, which would alleviate the other problem as well. But I think it should work pretty well for you. If it doesn't, maybe a two-pass solution, marking each element with its position in pass one, would break the problem down usefully? Hoping that helps, 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 ====================================================================== XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list 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
|