473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

finding the correct segment

20
Hi,

I have the following:

Expand|Select|Wrap|Line Numbers
  1. <start>
  2.     <segment Id="AAA">
  3.         <element Id="id">1</element>
  4.         <element Id="seq">122</element>
  5.         <element Id="seq2" Composite="yes">
  6.             <subelement Sequence="1">57002122338772</subelement>
  7.        </element>
  8.    </segment>
  9.    <segment Id="BBB">
  10.       <element Id="id">5</element>
  11.       <element Id="BBB02" Composite="yes">
  12.           <subelement Sequence="1">AS12121212</subelement>
  13.           <subelement Sequence="2">SA</subelement>
  14.       </element>
  15.    </segment>
  16.    <segment Id="BBB">
  17.       <element Id="id">1</element>
  18.       <element Id="BBB02" Composite="yes">
  19.           <subelement Sequence="1">12121212</subelement>
  20.           <subelement Sequence="2">HS</subelement>
  21.       </element>
  22.    </segment>
  23.    <segment Id="XXX">
  24.       <element Id="XXX01">C</element>
  25.       <element Id="XXX02">35</element>
  26.       <element Id="XXX03" Composite="yes">
  27.          <subelement Sequence="1">090</subelement>
  28.          <subelement Sequence="3">91</subelement>
  29.       </element>
  30.    </segment>
  31.    <segment Id="XXX">
  32.       <element Id="XXX01">C</element>
  33.       <element Id="XXX02">98</element>
  34.       <element Id="XXX03" Composite="yes">
  35.         <subelement Sequence="1">36</subelement>
  36.         <subelement Sequence="3">91</subelement>
  37.       </element>
  38.   </segment>
  39. ...
  40. </start>
  41.  
This code is repeated maybe 10 times and is defined by the id in element 'id' in segment 'AAA'. So the next lines of code will be
[code]
Expand|Select|Wrap|Line Numbers
  1.     <segment Id="AAA">
  2.         <element Id="id">2</element>
  3.         ...
  4.  
Now I have the Id, and I need to get a value from the proceeding XXX-segment, i.e. if my id is 4, I need to find the AAA-segment with id=4 and then a value in the following XXX-segment. But I'm wondering how I do this most correctly. I can probably use the position-function, but I'm thinking there must be a better way. Unfortunately my xpath skills are pretty limited. Can someone give me a hint?
Mar 18 '09 #1
3 2139
jkmyoung
2,057 Expert 2GB
When you say following, you mean the Id of that segment is 1 + the value of this id? eg id=5 in your example?

Assuming you're in a segment node:
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="segid" select="@Id"/>
  2. <xsl:variable name="elid" select="element[@Id='id']+1"/>
  3. <xsl:for-each select="../segment[@id = $segid][element[@Id='id'][.=$elid]]">
  4. ...
  5.  
Even if this isn't it, it should give you some sort of clue.
Mar 18 '09 #2
madshov
20
Ok. I mean if I have id=4, I first find the AAA-segment with id=4. Then my job will be to find the first XXX-segment with element id=XXX02's value set to 98 beneath it.

Imagine that the block I have shown in the thread is repeated within the start-tags, and only the values change. Ex. the id of the AAA-segment is incremented.

Hope I make myself clear :)
Mar 18 '09 #3
jkmyoung
2,057 Expert 2GB
I think I know what you mean now.
<xsl:for-each select="following-sibling::segment[@Id='XXX'][1]">
I don't understand why you wouldn't get the segment with value 35 though.

Another possibility:
Expand|Select|Wrap|Line Numbers
  1. <xsl:key name="previousAAA" match="segment" use="preceding-sibling::segment[@Id='AAA'][1]"/>
  2. ...
  3. while in aaa Segment:
  4.  
  5. <xsl:for-each select="key('previousAAA', .)[@Id='XXX']">
  6.  
maybe add [1] or [position()=last()].
Mar 19 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stephen S M WONG | last post by:
As C++ program supports objects with constructors/destructors/methods and data items, I'll assume C++ implementation on segment model computer, like a 80286 with different access restrictions on...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
1
by: Dr. Zharkov | last post by:
Hello. A problem in the following. In VB .NET 2003 I create the project and in file Form1.vb is written down the following code: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As...
5
by: druberego | last post by:
I read google and tried to find the solution myself. YES I do know that you can get undefined references if you: a) forget to implement the code for a prototype/header file item, or b) you forget...
3
by: Jeff | last post by:
Hi all, I'm wondering if there is a function that will return the xpath to a specific node given its context node. Essentially, I want the reverse of the document.evaluate functionality. I've...
4
by: jesjak | last post by:
hi all, can any one give me some explanation of "wat is .bss segment in object file" and what it will contain and difference between data segment and .bss segment.... help me.... thanks, jes
11
by: axlq | last post by:
Does anyone have a favored way of finding the geographic location of a user's IP address, so that a php script can include content relevant to that location? Reverse-lookup of the hostname isn't...
17
by: abhimanyu.v | last post by:
Hi Guys, I have one doubt. The test program is given below. It uses two way of finding out the offset of a variable in structure. I executed the program and found the same result. My question...
13
by: biplab | last post by:
for(i=0;i<256;i++) { hist=0; } for(i=0;i<height;i++) { for(j=0;j<width;j++) { k=(long int)rgb1; hist=hist+1;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.