XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Kevin YSubject: How do I do for-each on Elemenet_#'s? Please help!
Author: Kevin Y
Date: 01 Mar 2006 12:11 PM
Originally Posted: 01 Mar 2006 12:09 PM
Hi. I'm new to this forum as well as XSLT. I hope someone can help me solve this problem.<br> <br> I have the following XML (just part of it): <br> <br> <Segment-SDQ><br> <Element-355>CA</Element-355><br> <Element-66>9</Element-66><br> <Element-67_1>0091372090506</Element-67_1><br> <Element-380_2>428.000000</Element-380_2><br> <Element-67>0091372091009</Element-67><br> <Element-380>250.000000</Element-380><br> <Element-67_2>0091372091729</Element-67_2><br> <Element-380_1>375.000000</Element-380_1><br> <Element-67_3>0091372091919</Element-67_3><br> <Element-380_3>75.000000</Element-380_3><br> <Element-67_4>0091372092022</Element-67_4><br> <Element-380_4>310.000000</Element-380_4><br> <Element-67_5>0091372092023</Element-67_5><br> <Element-380_5>245.000000</Element-380_5><br> <Element-67_6>0091372092544</Element-67_6><br> <Element-380_6>716.000000</Element-380_6><br> <Element-67_7>0091372093052</Element-67_7><br> <Element-380_7>170.000000</Element-380_7><br> <Element-67_8>0091372093111</Element-67_8><br> <Element-380_8>85.000000</Element-380_8><br> <Element-67_9>0091372093345</Element-67_9><br> <Element-380_9>175.000000</Element-380_9><br> </Segment-SDQ><br> <br> What do I need to do as far :<br> <xsl:for-each select="Segment-SDQ/Element-67*"> The * means some code to replace there in order to repeat the loop for 67, 67_1, 67_2, 67_3, etc...<br> <br> Thanks.


Unknownsafeway.xsl


UnknownSafeway19523.xml

Postnext
Minollo I.Subject: How do I do for-each on Elemenet_#'s? Please help!
Author: Minollo I.
Date: 01 Mar 2006 12:41 PM
Something like...

<xsl:for-each select="Segment-SDQ/*[starts-with(local-name(), Element-67)]">
...
</xsl:for-each>

?
Minollo

Postnext
Kevin YSubject: How do I do for-each on Elemenet_#'s? Please help!
Author: Kevin Y
Date: 01 Mar 2006 05:04 PM
Thanks for the reply.

This is what the XLS looks like:

<xsl:for-each select="Transaction-830/Loop-LIN/Loop-FST/Segment-SDQ/*[starts-with(local-name(), Element-67)]"/>
<table id="DemandList1" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tbody>
<tr>
<td>
<b>DUNS: <xsl:value-of select="???"/></b>
</td>
</tr>
<tr>
<td>&#160;</td>
</tr>
<tr>
<td>
<table cellSpacing="1" cellPadding="2" width="100%" border="0">
<tbody>
<tr class="TDGridBrownRowTitle">
<td>Begin Date</td>
<td>End Date</td>
<td>Ship to DUNS</td>
<td>Planned Cases</td>
</tr>
<xsl:for-each select="Loop-FST">
<tr class="r{position() mod 2}">
<td>
<xsl:value-of select="Segment-FST/Element-373"/>
</td>
<td>
<xsl:value-of select="Segment-FST/Element-373_1"/>
</td>
<td>
<xsl:value-of select="???"/>
</td>
<td>
<xsl:value-of select="Segment-SDQ/Element-380_2"/>
</td>
</tr>
</xsl:for-each>
</tbody>
</table></td>
</tr>
<tr>
<td>&#160;</td>
</tr>
</tbody>
</table>
</xsl:for-each>

What should I place in place of the '???'= Element-67*

You see that I have Element-67, Element-67_1, _2, _3, _4, so on so forth and it need to xsl:for-each of them along with its corresponding elements.

Make sense?

Thanks for your help!

Postnext
Minollo I.Subject: How do I do for-each on Elemenet_#'s? Please help!
Author: Minollo I.
Date: 01 Mar 2006 05:22 PM
Kevin,
at that point you are already in context of any element that starts with "Element-67" (btw, make sure you put single quotes around Element-67 when you invoke the starts-with function; it won't work the way you expect right now); so, doing <xsl:value-of select="."/> should be what you want to do.

Minollo

Postnext
Kevin YSubject: How do I do for-each on Elemenet_#'s? Please help!
Author: Kevin Y
Date: 02 Mar 2006 08:39 AM
So there is no way I can loop any other elements(values) outside the Element-67? What should I do in order to loop Element-67 or Element-67_1, and Element-67_2 and so on?

Postnext
Minollo I.Subject: How do I do for-each on Elemenet_#'s? Please help!
Author: Minollo I.
Date: 02 Mar 2006 09:04 AM
Kevin,
I'm not sure I understand what you are asking.

The XSLT instruction:
<xsl:for-each select="Transaction-830/Loop-LIN/Loop-FST/Segment-SDQ/*[starts-with(local-name(), 'Element-67')]">
...
</xsl:for-each>

...will loop over *any* element child of "Transaction-830/Loop-LIN/Loop-FST/Segment-SDQ" and whose name *starts with* "Element-67".

So, if Segment-SDQ as children elements named "Element-67" or "Element-67_1" or "Element_67_whatever_you_want_to_write_here", that for loop will cycle through all those elements. It will not cycle on children elements of Segment-SDQ named "Element-87" or "Element-peppino".

Once you are inside the for-each execution, the "context" will be your "Element-67*" node; which means that "." will be whatever "Element-67*" is the current iteration node of the for loop.

Does this help?
Minollo

Postnext
Kevin YSubject: How do I do for-each on Elemenet_#'s? Please help!
Author: Kevin Y
Date: 02 Mar 2006 09:22 AM
Minollo,

Thank you so much for all the help. I got it to work but...

What if I need to loop other element that is outside the Segment-SDQ/Element-67* loop? For Example:

<xsl:for-each select="Transaction-830/Loop-LIN/Loop-FST/Segment-SDQ/*[starts-with(local-name(), 'Element-67')]">
<xsl:value-of select="."/>

<xsl: for each select="Transaction-830/Loop-LIN/Loop-FST/Segment-FST">
<xsl:value-of selected="Element-380:>
</xsl:for-each>

</xsl: for-each>

What do I need to do?

Postnext
Minollo I.Subject: How do I do for-each on Elemenet_#'s? Please help!
Author: Minollo I.
Date: 02 Mar 2006 09:33 AM
...unless the loops need to be nested, those would qualify as two separate loops; you should rewrite them as:

<xsl:for-each select="Transaction-830/Loop-LIN/Loop-FST/Segment-SDQ/*[starts-with(local-name(), 'Element-67')]">
<xsl:value-of select="."/>
</xsl:for-each>

<xsl: for each select="Transaction-830/Loop-LIN/Loop-FST/Segment-FST/*[starts-with(local-name(), 'Element-38')]">
<xsl:value-of selected=".">
</xsl: for-each>

Minollo

Postnext
Kevin YSubject: How do I do for-each on Elemenet_#'s? Please help!
Author: Kevin Y
Date: 02 Mar 2006 09:56 AM
They need to be nested. Loop#2 inside the Loop#1 but the Loop#2 needs to call elements that is outside the Loop#1.

Transaction-830
Loop-N1/Segment-N1/
[Element-97]
[Element-98]
[Element-99]
Loop-LIN/Loop-FST/Segment-SDQ/
[Element-67]
[Element-67_1]
[Element-67_2]

So I need to xsl:for-each Element-67* and inside of that I want to xsl:for-each Loop-N1/Segment-N1/ and return [Element-97], [Element-98], [Element-99].


Thansk for your help. I cannot figure this out without people like you.

Postnext
Minollo I.Subject: How do I do for-each on Elemenet_#'s? Please help!
Author: Minollo I.
Date: 02 Mar 2006 10:06 AM
If the loops need to be nested, then you have to play with paths in expressions a bit more...

<xsl:for-each select="Transaction-830/Loop-LIN/Loop-FST/Segment-SDQ/*[starts-with(local-name(), 'Element-67')]">
<xsl:value-of select="."/>
<xsl: for each select="../../Segment-FST/*[starts-with(local-name(), 'Element-38')]">
<xsl:value-of selected=".">
</xsl: for-each>
</xsl:for-each>

Postnext
Kevin YSubject: How do I do for-each on Elemenet_#'s? Please help!
Author: Kevin Y
Date: 02 Mar 2006 10:42 AM
It didn't work. I need to call different Elements inside the inner loop not a sequence of elements (ex: Loop-FST/Segment-FST/Element-373, Loop-FST/Segment-FST/Element-373_1, Loop-FST/Segment-SDQ/Element-380_4)

I have attached xls and xml file to show you what I have done.

I hope you can help.


Unknownsafeway(2).xsl


UnknownSafeway19523(1).xml

Postnext
Minollo I.Subject: How do I do for-each on Elemenet_#'s? Please help!
Author: Minollo I.
Date: 02 Mar 2006 11:15 AM
Kevin,
taking a quick look at your code and the structure of the document, I tend to think you don't need to second loop... I think you can change...

<xsl:for-each select="../../Loop-FST">
<tr class="r{position() mod 2}">
<td>
<xsl:value-of select="Segment-FST/Element-373"/>
</td>
<td>
<xsl:value-of select="Segment-FST/Element-373_1"/>
</td>
<td>
<xsl:value-of select="Segment-FST/Element-373_1"/>
</td>
<td>
<xsl:value-of select="Segment-SDQ/Element-380_2"/>
</td>
</tr>
</xsl:for-each>


...into...

<tr class="r{position() mod 2}">
<td>
<xsl:value-of select="../../Segment-FST/Element-373"/>
</td>
<td>
<xsl:value-of select="../../Segment-FST/Element-373_1"/>
</td>
<td>
<xsl:value-of select="../../Segment-FST/Element-373_1"/>
</td>
<td>
<xsl:value-of select="../Element-380_2"/>
</td>
</tr>

Does that generate what you are looking for?
Minollo

Postnext
Kevin YSubject: How do I do for-each on Elemenet_#'s? Please help!
Author: Kevin Y
Date: 02 Mar 2006 12:02 PM
I need to do another for-each since those elements needs to repeat according to the Element-67*

If you see the XML schema - I need to make Element-67* to be the main loop and another sets of elements that goes with it. Please my attached screenshot.


UnknownXSLT.gif

Postnext
Minollo I.Subject: How do I do for-each on Elemenet_#'s? Please help!
Author: Minollo I.
Date: 02 Mar 2006 01:09 PM
Kevin,
please take a look at the attached modified stylesheet.

I'm not sure this outputs what you need, mostly because I'm not positive about the relationship between the DUNS and the fields in columns #1 and #2 of your image... I tried to guess that in this expression:

<xsl:for-each select="../../../Loop-FST[Segment-SDQ/*[local-name()=$element67name] = $element67value]">

...basically assuming that for each DUNS you are listing all the Element-373(_1) information that is available in any Loop-FST occurence where the same DUNS is listed in the same Element67* element... That's a complete guess on my side.

I've also grouped the DUNS (because otherwise you would endup with plenty of duplicate information), but again, I'm not sure that grouping is doing exactly what you need.

Take a look; you should be able to tweak things from here to make it work the way you need.

Minollo


Documentsafeway(3).xsl
modified xslt

Postnext
Kevin YSubject: How do I do for-each on Elemenet_#'s? Please help!
Author: Kevin Y
Date: 02 Mar 2006 03:58 PM
For each DUNS i want to list all the Element-373(_1), 380_2, 234(_1), 356, 357, 355_1 information that is available in any Loop-LIN occurence where the same DUNS is listed in the same Element67* element...

I try to play around a bit more but I keep getting the same results on Element-373(_1), 380_2, 234(_1), 356, 357, 355_1 for different DUNS.

This is so complicated. I wish I can change the XML format....nothing is easy here.

Thanks a million. Can I send you some cookies?


Unknownsafeway(4).xsl


UnknownSafeway26878.xml

Postnext
Minollo I.Subject: How do I do for-each on Elemenet_#'s? Please help!
Author: Minollo I.
Date: 02 Mar 2006 04:25 PM
Kevin,
unfortunately I'm not able to spend more time on this; but I would suggest that you try using the step-by-step debugging in Stylus Studio; I did find it very useful while playing with your XSLT setting a breakpoint inside the loops and running XPath instructions (Debug > Watch Window) like .., ../.., ../../../Loop-LIN and so on to understand where the context was and how I could reach other items.

Of course cookies are very welcome :)
Minollo

Postnext
Kevin YSubject: How do I do for-each on Elemenet_#'s? Please help!
Author: Kevin Y
Date: 03 Mar 2006 08:59 AM
I play around some more yesterday without luck. Thanks for your help tho!

Posttop
Minollo I.Subject: How do I do for-each on Elemenet_#'s? Please help!
Author: Minollo I.
Date: 03 Mar 2006 09:20 AM
You may want to try posting your problem on the xsl-list at mulberrytech.com

Thanks,
Minollo

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.