xsl-list
[Top] [All Lists]

RE: [xsl] Capturing position as a number

2009-03-18 14:17:40
Hi Charles,

You can do something like:

<xsl:variable name="currentpos" select="position()"/>

Or:

<xsl:variable name="currentpos" select="count(preceding-sibling::CONDITION) + 
1"/>

Your expression:

<xsl:variable name="CurrentCond"><xsl:value-of 
select="CONDITION[position()]"/></xsl:variable>

Creates a root tree fragment with all CONDITION elements that are a child of 
the context, e.g. the CONDITION element that was matched. I guess the 
[position()] predicate is not restricting by the way. When looking for some 
OTHERELEM at the same position, do something like:

<xsl:variable name="OtherElem" select="OTHERELEM[position() = $currentpos]"/>

Or perhaps prepend a relative path if it is located elsewhere..

Kind regards,
Geert




Drs. G.P.H. Josten
Consultant


http://www.daidalos.nl/
Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665 JZ Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
http://www.daidalos.nl/
KvK 27164984
De informatie - verzonden in of met dit emailbericht - is afkomstig van 
Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit 
bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit 
bericht kunnen geen rechten worden ontleend.


From: Charles Flanders [mailto:cflanders(_at_)vasont(_dot_)com]
Sent: woensdag 18 maart 2009 19:07
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Capturing position as a number

I need to capture an elements position as an integer to a
variable so  I
can  use that number in capture the text from another element that
shares the same position number in another part of the tree.

My XML looks something like this:

<Document>
<CONDITION>
<HYPERPROC linkend="M16-66A.-HP1">Webbing straps removed</HYPERPROC>
</CONDITION>
<CONDITION>
<HYPERPROC linkend="M16-66A.-HP2">Remote Terminal Unit
Removed</HYPERPROC></CONDITION>
</Document>

My template:


<xsl:template match="CONDITION">
<xsl:variable name="CurrentCond"><xsl:value-of
select="CONDITION[position()]"/></xsl:variable>
<eqpconds>
<eqpconds-setup-item><condition><xsl:value-of select="."/></condition>
<itemref><link xmlns:xlink="http://www.w3.org/1999/xlink";>
            <xsl:attribute name="linkaction">prompt</xsl:attribute>
            <xsl:attribute name="linktype">goto</xsl:attribute>
             <xsl:attribute namespace="http://www.w3.org/1999/xlink";
name="href">
<xsl:value-of select="//nameloc[$CurrentCond]/nmlist"/>
<xsl:text>.xml</xsl:text></xsl:attribute>
             <xsl:attribute
name="xreftype">wp</xsl:attribute><prompt><xsl:value-of select="."/>
</prompt></link>
</itemref>
</eqpconds-setup-item></eqpconds>
</xsl:template>

<xsl:template match="HYPERPROC"/>

Everything I've tried always returns the value of "1". I don't
understand this, I have two CONDITION elements, shouldn't the
second one
have a position value of "2". Any help would be appreciated.






--

*Charles Flanders*


<mailto:cflanders(_at_)vasont(_dot_)com>



--~------------------------------------------------------------------
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>
--~--




--~------------------------------------------------------------------
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>