473,789 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

finding the correct segment

20 New Member
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 2155
jkmyoung
2,057 Recognized Expert Top Contributor
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 New Member
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 Recognized Expert Top Contributor
I think I know what you mean now.
<xsl:for-each select="followi ng-sibling::segmen t[@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
1966
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 code segment / data segment / etc., will force all objects to be resided in a code segment, so that executable code can be there as well as data. And effectively bypassing all segment model. Any comments on the above?
65
12619
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 method was a piece of C code which turned out to be incorrect and incomplete but by modifieing it would still be usuable. The first method was this piece of text:
1
320
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 System.EventArgs) Handles MyBase.Load 'Create the data: CreateData() 'Error End Sub
5
11362
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 to pass all the necessary object files to the linker. Neither of those are my problem. Please bear with me as the question I ask is rather long and I think it's beyond a CS101 level of linker stupidity. If it is a stupid CS101 mistake I'm making...
3
2266
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 seen examples where people build up the xpath themselves by walking the DOM, but I thought there has to be a better way. I've included a simple example of this, based on code from the Solvent project at MIT. This code works reasonably well, but...
4
6987
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
26303
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 reliable and often doesn't work, especially if the returned hostname ends with .com, .net, ..info, .biz or other tld that doesn't reveal geographic location. I also see a bunch of commercial services that offer a "country whois" function for a...
17
3789
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 is what is difference between 1) (unsigned long) &((struct foobar *)0)->foo and
13
1387
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
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10193
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4089
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.