Solved

[XPATH] query problem with siblings

Posted on 2006-11-13
4
532 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 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