Solved

[XPATH] query problem with siblings

Posted on 2006-11-13
4
520 Views
Last Modified: 2012-06-21
<data>

<record id="243">XTFC</record>
<record id="634">ABCD</record>
<record id="734">FTGD</record>
<record id="933">VCFG</record>
<record id="352">QDEW</record>

</data>

I'm a bit lost. If I take the previous xml data, how can I get the following-sibling of the element with @id="734"?  Using /data/following-sibling::record[@id='734'] doesn't work obviously, as it takes out that one record with id=734, and that sub-recordset doesn't have any siblings.

I could loop through all records until I find the right id, and then I can use the following-sibling, like below. I would have to do this twice, for the preceding-sibling as well.

<xsl:variable name="next">
      <xsl:for-each select="/data/record">
            <xsl:if test="@id='734'"><xsl:value-of select="following-sibling::*"/></xsl:if>
      </xsl:for-each>
</xsl:variable>

Isn't there a more direct way?
0
Comment
Question by:grexx
  • 3
4 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 250 total points
ID: 17936423
Hi grexx,

/data/record[@id='734']/following-sibling::record[1]

Cheers!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17936429
grexx,

you need to follow a path
so first follow the path to the record with @id = 734
then step on the following-sibling axis, pick record
and use the first [1], if you only want one

cheers

Geert
0
 
LVL 1

Author Comment

by:grexx
ID: 17936848
Thanks Gertone! I see that I need to dive into XPATH a bit more.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17936896
welcome
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now