xsl-list
[Top] [All Lists]

[xsl] Re: Finding the position of an element wrt to other element

2010-11-21 00:33:17
Hi there,

with 342, it means the position of that b element which have child c
and relative to first b element (whether it has child c or not); as
specified my xpath

="//b[c][not(@name=preceding::b[child::c]/@name)]/@name

With the above xpath in my sample xml three b element will be select,
namely, b[(_at_)name='3'], b[(_at_)name='4'] and b[(_at_)name='2'], now the 
position
of these above selected b elements relative to first 'b' element
(b[(_at_)name='1']) will be 3 and 4 for the b's which are child of first
<a> and 2 for the b in second <a>.

Hope this give u a clear picture of the desired output.... your kind
responce is awaited....thanks.....

Date: Fri, 19 Nov 2010 15:46:27 +0530
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
From: Rashi Bhardwaj <rashi(_dot_)bhardwaj(_at_)gmail(_dot_)com>
Subject: Finding the position of an element wrt to other element
Message-ID: 
<AANLkTinNE=-iCAvs0puyx7GTnOB=yh_QFfJrRFNV9BnR(_at_)mail(_dot_)gmail(_dot_)com>

Hi,

I want the position of an element (there is a condition for selecting
that element) relative to other element

Input XML:
<test>
<a>
<b name ='1'></b>
<b name ='2'></b>
<b name ='3'>
<c></c>
</b>
<b name ='4'>
       <c></c>
       <c></c>
</b>
<b name ='4'>
       <c></c>
       <c></c>
</b>
</a>
<a>
<b name ='1'></b>
<b name ='2'>
<c></c>
</b>
<b name ='3'></b>
<b name ='4'>
       <c></c>
</b>
</a>
</test>

XSL I using:

<xsl:template match="/">
               <html>
                       <body>
                       <table>
                               <tbody>
                                       <tr>
                                               <th>
                                               <xsl:value-of 
select="$CustomSelect"/>
                                               </th>
                                       </tr>
                               </tbody>
                       </table>
                       </body>
               </html>
       </xsl:template>
       <xsl:variable name="CustomSelect">
                       <xsl:text>position: </xsl:text>
                               <xsl:call-template name="test">
                               </xsl:call-template>
               </xsl:variable>
               <xsl:template name="test">
 <xsl:call-template name="test2">
 <xsl:with-param name="node" select="//b[c][not(@name
=preceding::b[child::c]/@name)]/@name"/>
   </xsl:call-template>
    </xsl:template>
<xsl:template name="test2">
<xsl:param name="node"/>
<xsl:for-each select="$node">
<xsl:value-of select="position()"/>
<xsl:if test="position()!=last()"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Output I m getting is position 123, but i want it should count all b
from top to end at any level and give relative position like here it
should give 342. I m getting how to go ahead...please help  me out
thanks......

Rashi Bhardwaj

------------------------------

Date: Fri, 19 Nov 2010 11:56:44 +0100
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
From: Wolfgang Laun <wolfgang(_dot_)laun(_at_)gmail(_dot_)com>
Subject: Re: [xsl] Finding the position of an element wrt to other element
Message-ID: 
<AANLkTi=V_NctD+9Q0pH6wUcsJh=FHnxn0z3XFzUBJcZP(_at_)mail(_dot_)gmail(_dot_)com>

Sorry, but I don't understand the problem. I fail to see where "342"
(or 3, 4, 2?) should come from.

When you say "relative position", then there's always two elements
involved, and you'll have to specify for both how they can be
identified.

Also, what unit are you thinking of when you mean "relative position"?
Number of elements between the first and last <a>
here
  <a p=3D"1"/><b/><a/><a/><b/><a/>
could be 4 (including b) or 2 (<a> only).

Are you using XSLT 2.0? If not, I won't be able to help you at all.
-W

On 19 November 2010 11:16, Rashi Bhardwaj 
<rashi(_dot_)bhardwaj(_at_)gmail(_dot_)com> wrote:
Hi,

I want the position of an element (there is a condition for selecting
that element) relative to other element

Input XML:
<test>
<a>
<b name =3D'1'></b>
<b name =3D'2'></b>
<b name =3D'3'>
<c></c>
</b>
<b name =3D'4'>
=A0 =A0 =A0 =A0<c></c>
=A0 =A0 =A0 =A0<c></c>
</b>
<b name =3D'4'>
=A0 =A0 =A0 =A0<c></c>
=A0 =A0 =A0 =A0<c></c>
</b>
</a>
<a>
<b name =3D'1'></b>
<b name =3D'2'>
<c></c>
</b>
<b name =3D'3'></b>
<b name =3D'4'>
=A0 =A0 =A0 =A0<c></c>
</b>
</a>
</test>

XSL I using:

<xsl:template match=3D"/">
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<html>
=A0 =A0 =A0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 =A0 =A0 =A0 =A0 =A0 =A0<xsl:call-=
template name=3D"test">
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0</xsl:call=
-template>
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0</xsl:variable>
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<xsl:template name=3D"test">
=A0<xsl:call-template name=3D"test2">
=A0<xsl:with-param name=3D"node" select=3D"//b[c][not(@name
=3Dpreceding::b[child::c]/@name)]/@name"/>
=A0 =A0</xsl:call-template>
=A0 =A0 </xsl:template>
<xsl:template name=3D"test2">
<xsl:param name=3D"node"/>
<xsl:for-each select=3D"$node">
<xsl:value-of select=3D"position()"/>
<xsl:if test=3D"position()!=3Dlast()"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Output I m getting is position 123, but i want it should count all b
from top to end at any level and give relative position like here it
should give 342. I m getting how to go ahead...please help =A0me out
thanks......





Rashi Bhardwaj

--~------------------------------------------------------------------
XSL-List info and archive: =A0http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



------------------------------

Date: Fri, 19 Nov 2010 07:58:56 -0400
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
From: Piet van Oostrum <piet(_at_)vanoostrum(_dot_)org>
Subject: Re: [xsl] Finding the position of an element wrt to other element
Message-ID: 
<19686(_dot_)26240(_dot_)867883(_dot_)867072(_at_)cochabamba(_dot_)vanoostrum(_dot_)org>

Rashi Bhardwaj wrote:

 > Output I m getting is position 123, but i want it should count all b
 > from top to end at any level and give relative position like here it
 > should give 342. I m getting how to go ahead...please help  me out
 > thanks......
 >

If you do:

<xsl:for-each select="$node">
 <xsl:value-of select="position()"/>
</xsl:for-each>

You will always get 1 2 3 ... whatever the input is (the nember depending on 
the size of the input)
--
Piet van Oostrum
Cochabamba. URL: http://pietvanoostrum.com/
Nu Fair Trade woonartikelen op http://www.zylja.com

------------------------------

End of xsl-list Digest
***********************************




-- 


Rashi Bhardwaj

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>