Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old February 18th, 2006, 08:25 PM
Steve
Guest
 
Posts: n/a
Default xpath expression to find which element

Hello.. I have been trying to figure this out for the last hour, but I am
baffled... I'm hoping someone can help!

I'm trying to write an xpath expression to find the position of the node
with value "c" in the following xml. The result I'm looking for in this case
should be 3. Does anyone have any ideas?

<?xml version="1.0" encoding="UTF-8"?>
<TopNode>
<FieldDefinition>a</FieldDefinition>
<FieldDefinition>b</FieldDefinition>
<FieldDefinition>c</FieldDefinition>
<FieldDefinition>d</FieldDefinition>
<FieldDefinition>e</FieldDefinition>
</TopNode>

My idea was something like:

/*/position(". = 'c'")

But that doesn't work.

Could anyone please help! Thank you very much in advance.
--
Steve
  #2  
Old February 18th, 2006, 08:45 PM
Dimitre Novatchev
Guest
 
Posts: n/a
Default Re: xpath expression to find which element

/*/*[.='c']


Cheers,
Dimitre Novatchev




"Steve" <smsinger3@newsgroup.nospam> wrote in message
news:6320D8CE-180D-4173-92D7-771D2CDB7FE1@microsoft.com...[color=blue]
> Hello.. I have been trying to figure this out for the last hour, but I am
> baffled... I'm hoping someone can help!
>
> I'm trying to write an xpath expression to find the position of the node
> with value "c" in the following xml. The result I'm looking for in this
> case
> should be 3. Does anyone have any ideas?
>
> <?xml version="1.0" encoding="UTF-8"?>
> <TopNode>
> <FieldDefinition>a</FieldDefinition>
> <FieldDefinition>b</FieldDefinition>
> <FieldDefinition>c</FieldDefinition>
> <FieldDefinition>d</FieldDefinition>
> <FieldDefinition>e</FieldDefinition>
> </TopNode>
>
> My idea was something like:
>
> /*/position(". = 'c'")
>
> But that doesn't work.
>
> Could anyone please help! Thank you very much in advance.
> --
> Steve[/color]


  #3  
Old February 18th, 2006, 10:05 PM
Peter Flynn
Guest
 
Posts: n/a
Default Re: xpath expression to find which element

Steve wrote:[color=blue]
> Hello.. I have been trying to figure this out for the last hour, but I am
> baffled... I'm hoping someone can help!
>
> I'm trying to write an xpath expression to find the position of the node
> with value "c" in the following xml. The result I'm looking for in this case
> should be 3. Does anyone have any ideas?
>
> <?xml version="1.0" encoding="UTF-8"?>
> <TopNode>
> <FieldDefinition>a</FieldDefinition>
> <FieldDefinition>b</FieldDefinition>
> <FieldDefinition>c</FieldDefinition>
> <FieldDefinition>d</FieldDefinition>
> <FieldDefinition>e</FieldDefinition>
> </TopNode>
>
> My idea was something like:
>
> /*/position(". = 'c'")
>
> But that doesn't work.
>
> Could anyone please help! Thank you very much in advance.[/color]

position() won't help you here because it's a null function (no
arguments).

<xsl:value-of select="count(/*/*[.='c']/preceding-sibling::*)+1"/>

This will work provided you know that no other elements types apart from
FieldDefinition are permitted in the content model of TopNode. If other
elements types are allowed, then you will have to qualify the element
nodes located by the preceding-sibling axis.

///Peter
  #4  
Old February 19th, 2006, 04:05 AM
Dimitre Novatchev
Guest
 
Posts: n/a
Default Re: xpath expression to find which element

Sorry, was misled by the subject.

Peter Flyn has provided an answer.

Another possibility is to use <xsl:number> , depending on what you mean
by "the position of the element"

Cheers,
Dimitre Novatchev


"Dimitre Novatchev" <dimitren@tpg.com.au> wrote in message
news:43f78548$0$12881$892e7fe2@authen.yellow.readf reenews.net...[color=blue]
> /*/*[.='c']
>
>
> Cheers,
> Dimitre Novatchev
>
>
>
>
> "Steve" <smsinger3@newsgroup.nospam> wrote in message
> news:6320D8CE-180D-4173-92D7-771D2CDB7FE1@microsoft.com...[color=green]
>> Hello.. I have been trying to figure this out for the last hour, but I am
>> baffled... I'm hoping someone can help!
>>
>> I'm trying to write an xpath expression to find the position of the node
>> with value "c" in the following xml. The result I'm looking for in this
>> case
>> should be 3. Does anyone have any ideas?
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <TopNode>
>> <FieldDefinition>a</FieldDefinition>
>> <FieldDefinition>b</FieldDefinition>
>> <FieldDefinition>c</FieldDefinition>
>> <FieldDefinition>d</FieldDefinition>
>> <FieldDefinition>e</FieldDefinition>
>> </TopNode>
>>
>> My idea was something like:
>>
>> /*/position(". = 'c'")
>>
>> But that doesn't work.
>>
>> Could anyone please help! Thank you very much in advance.
>> --
>> Steve[/color]
>
>[/color]


 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles