A row position in a for?

25 views
Skip to first unread message

Mike Rodriguez

unread,
Sep 28, 2009, 5:39:57 PM9/28/09
to Oracle Service Bus
Hey again Jeff

First of all
Hello!! How had you been! Hope everything it's just quite fine!

Well right now I'm still learning, you know. As usual every new
project has a new challenge.
Right now I'm facing a picky issue.

I'm trying to transform a XML. The issue that I see in here is that
this XML isn't well defined, I'm not saying unwell formed, because it
has the right tags in the right place.
What I'm facing is that one tag contains another tag, but there is no
attribute or value that could relate them.
Imagine something like this
<mainTag>
<oneFather>
<oneSon>
<firstValue>15</firstValue>
<secondValue>Hello</secondValue>
<anotherSon>
<someOther>This is a sample<someOther>
</anotherSon>
</oneSon>
</oneFather>
<oneFather>
<oneSon>
<firstValue>25</firstValue>
<secondValue>Wassup</secondValue>
<anotherSon>
<someOther>This is a sample for testing<someOther>
</anotherSon>
</oneSon>
</oneFather>
</mainTag>

And well based on that I want to know, because I'm pretending to
create an XML like this

<newMainTag>
<theFirstValues>
<firstIteration>15</firstIteration>
<secondIteration>25</secondIteration>
</theFirstValues>
<someOtherThing>
<secondValues>
<firstIteration>
<value>Hello</value>
<valueTwo>This is a sample</valueTwo>
</firstIteration>
<secondIteration>
<value>Wassup</value>
<valueTwo>This is a sample for testing</valueTwo>
</secondIteration>
</secondValues>
</someOtherThing>
</newMainTag>

What I just can't understand "how to do it" it's, if I don't have any
item to relate and understand wich <oneSon> I'm mapping to the
<firstIteration> and <secondIteration> how could I do it.
Could be possible to know in wich row you're standing on the "for"
loop?

I mean, my question will be, could this be done by XQuery?

Please help me out, I had been trying a couple of things but I just
can't...

You know I'll always be thankful!!

Have a gr8 day!!
Greetings!

Mike

Jeff

unread,
Sep 29, 2009, 2:20:50 AM9/29/09
to Oracle Service Bus
Hi Mike,
You can easily know which iteration you are in. The For-Each
looping structure allows you to define and index variable and a count
variable. The index variable holds the current row you are processing
while the count variable contains the total number of iterations the
For-Each loop will make.

I'll take a closer look at this as time permits. Hopefully one of
our group members will have some input on this also. One thing to note
is that the Google group for the OSB product is fairly small compared
to the Yahoo group. You might try posting your question there too, so
that we get some more eyes on the problem.

- Jeff

Mike R

unread,
Sep 29, 2009, 2:19:07 PM9/29/09
to Oracle Service Bus
Thanks a lot Jeff,

Let me post it in there also!

Thanks in advance.
And well, about the detail on the For Each, I'm pretending to do this
in a single XQuery transformation file.

But I will take a look at the for each, because I'll feed the OSB with
an XML and I need to transform it entirely and I was doing this with a
single Replace step, using the XQuery file.

Anyway, thanks a lot, for your help, and let me post it there.
I'll be waiting on any of your posts to see if you published something
related with.

Have a great day my friend!

Regards,
_
Mike

Mike R

unread,
Oct 12, 2009, 2:00:22 PM10/12/09
to Oracle Service Bus
For the people who's related with this Group.

Just if you're wondering if I found a way to solve the position where
I'm standing in the moment the for is looping, you can easily do it by
setting a variable on the "at" section in the FOR definition, this
way.

for $theForVar at $thePositionVar in $someXML/in/the/route

then every time the for loops, the loop row count, will be stored in
$thePositionVar variable.

Hope this helps, because even many XQuery references mentions it, it's
sometimes difficult to entirely understand the whole functionality.

Thanks to all who helped me...

Regards

_
Mike
Reply all
Reply to author
Forward
0 new messages