Click to See Complete Forum and Search --> : XPATH 2.0 Help


dako
01-06-2005, 01:10 PM
Hi, I need some help here. I have the following

...
<page>
<objectives>
<objective>Objective 1</objective>
<objective>Objective 2</objective>
</objective>
<page>
<page>
<objref num="2"/>
...
</page>
<page>
<objref num="1"/>
...
</page>
...

I need an XPATH expression (1.0 or 2.0) that automatically retrives the contents of the 'objective[n]' element from the 'objref' element for an id="n" ('n' is an integer)

for example if <objref num="1"/> I need the contents inside of the first objective element

Is that possible?
I tried something like this from the 'objref' element:

(../../page[1]/objectives/objective)[@num]

but this does't return anything.

an expression like:
(../../page[1]/objectives/objective)[1]

returns without problems the value of the first objective "Objective 1"

Any ideas?

Alantin
01-11-2005, 08:21 AM
Basically you want to match num attribute with the objective's position. First put the num attribute in a variable, then match the object's position predicate with the value of the num variable. Like this:

<xsl:template match="objref">
<xsl:variable name="num" select="@num"/>
<xsl:value of select="/page/objectives/objective[position()=$num"/>
</xsl:template>