This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Position of a Child


Hi,

Thanks for your answer, the input data I have is pretty simple:
<myXML>
<ContextNode>
	<Child1/>
	<Child3/>
	<Child4/>
	...
	<Childn/>
</ContextNode>
<ContextNode>
	<Child1/>
	<Child4/>
	...
	<Childn/>
</ContextNode>
...
</myXML>

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.

And problem about all this is that I have to treat specially childs
that are in certain positions.

Hope now is clearer :)
Frank.

-----Original Message-----
From: Wendell Piez [mailto:wapiez@mulberrytech.com]
Sent: jueves, 20 de septiembre de 2001 20:58
To: xsl-list@lists.mulberrytech.com
Subject: Re: [xsl] Position of a Child


Frank,

What you mean by "position of that child inside the context node" is 
actually a bit problematic, possibly meaning any of a number of things. How 
to get it depends both on what you mean, and what your input data looks
like.

For starters, you could try 
(count(*[name()=$NodeName]/preceding-sibling::*) + 1) -- that is, 1 + the 
number of the node's preceding element siblings. If you have mixed content 
(and thus the siblings you want to count include text nodes), or if there's 
some other wrinkle (such as more than one child node being named 
$NodeName), come back.

position() isn't very useful because it returns the position of the context 
node within the current node list, which isn't what you want. You could 
make it be what you want by doing something like:

<xsl:for-each select="*">
   <xsl:if test="name()=$NodeName">
     <xsl:value-of select="."/>
     <xsl:value-of select="position()"/>
   </xsl:if>
</xsl:for-each>

But again, I'm making assumptions about what you really want -- and you can 
see this is more roundabout than simple counting the preceding siblings.

Cheers,
Wendell


At 02:17 PM 9/20/01, you wrote:
>I'm having problems getting the child's position() of the context node.
>I reference the child by its name (stored in a variable), like this:
>
><xsl:value-of select="*[name()=$NodeName]"/>
>
>What I would like to get is the position of that child inside the context
>node.


======================================================================
Wendell Piez                            mailto:wapiez@mulberrytech.com
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]