[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Counting and Rearranging Nodes

Subject: Counting and Rearranging Nodes
From: "rostom aghanian" <rostom@xxxxxxxx>
Date: Thu, 22 Jun 2006 04:14:37 +0800
rostom aghanian
Hello,
I need some help on traversing an XML structure and outputting the entries in
a specific format. Here it goes....

My input structure looks something like this:

<Root>
  <Item>
      <Line_No>901</Line_No>
      <Amount>50.00</Amount>
  </Item>
  <Item>
    <Line_No>801</Line_No>
    <Amount>60.00</Amount>
  </Item>
  <Item>
    <Line_No>802</Line_No>
    <Amount>77.00</Amount>
  </Item>
  <Item>
    <Line_No>806</Line_No>
    <Amount>99.00</Amount>
  </Item>
  <Item>
    <Line_No>1002</Line_No>
    <Amount>3.00</Amount>
  </Item>
  <Item>
    <Line_No>1003</Line_No>
    <Amount>5.00</Amount>
  </Item>
</Root>

For my output I want something like the following:

<Root>
  <New_Item>
    <Line_No>801</Line_No>
    <Line_No_Og>801</Line_No_Og>
    <Amount>60.00</Amount>
  </New_Item>
  <New_Item>
    <Line_No>802</Line_No>
    <Line_No_Og>802</Line_No_Og>
    <Amount>77.00</Amount>
  </New_Item>
  <New_Item>
    <Line_No>803</Line_No>
    <Line_No_Og>806</Line_No_Og>
    <Amount>99.00</Amount>
  </New_Item>
  <New_Item>
    <Line_No>901</Line_No>
    <Line_No_Og>901</Line_No_Og>
    <Amount>60.00</Amount>
  </New_Item>
  <New_Item>
    <Line_No>1001</Line_No>
    <Line_No_Og>1002</Line_No_Og>
    <Amount>3.00</Amount>
  </New_Item>
  <New_Item>
    <Line_No>1002</Line_No>
    <Line_No_Og>1003</Line_No_Og>
    <Amount>5.00</Amount>
  </New_Item>
</Root>

Explanation and a few important points:
- Basically, I am trying to get the items renumbered based on their Line_No
element.

- The Line_No element will never end with a 00 (i.e. 800, 900, 1000).

- The Line_No element may skip (i.e. 801, 802, 806), but in my output I want
to keep them ordered (i.e. 801, 802, 803), as demostrated in the above XML
snippets.

- The result does not need to have the Line_No or Line_No_Og elements in
order, but it does need to restart the Line_No_Og numbering based on the
hundreth group the Line_No element is in. For example:
  801  --> 801  (begin 800 group)
  802  --> 802
  806  --> 803  (notice new Line_No is continuous, wheras original skipped)
  901  --> 901  (notice numbering re-starts at the 1s for a new group (900s))
  1002 --> 1001 (notice numbering re-starts at the 1s for a new group
(1000s))
  1003 --> 1002 (numbering continues consecutively in the 1000's group)

- And lastly, keep in mind that the Line_No elements can go up to the max
(i.e. 899, 999, and 1099).

Any help would be greatly appreciated. Thanks in advance.

rostom

--
___________________________________________________
Play 100s of games for FREE! http://games.mail.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.