473,398 Members | 2,212 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,398 software developers and data experts.

XSLT Question

Hello,

I have a following situation..
XML Document contains
<PurchaseOrder>
<LineItems>
<LineItem>
<Description></Description>
</LineItem>
<LineItem>
<Description></Description>
</LineItem>
</LineItems>
<Comments>
<Comment>
<NumberInCollection>1</NumberInCollection>
</Comment>
<Comment>
<NumberInCollection>2</NumberInCollection>
</Comment>
</Comments>
</PurchaseOrder>
When I am looping through Each Line Item using XSLT - I need to also
get corresponding comment for that line item - I have
NumberInCollection which ties with appropriate LineItem but I dont
know how to get this number when I am looping through Each LineItem.

Any Help will be very much apprecieated!

Thanks

AZXML
Jul 20 '05 #1
3 1650
sh*******@hotmail.com (Just Curious) wrote in message news:<d2**************************@posting.google. com>...
I have
NumberInCollection which ties with appropriate LineItem but I dont
know how to get this number when I am looping through Each LineItem.


This is a piece of poor DTD / Schema design - no wonder your XSLT is a
problem.
What connects these two nodes ? In your example, then there's nothing
robust that does it.
For a simple life with XML, then do it by containment:

<PurchaseOrder>
<LineItems>
<LineItem>
<Description></Description>
<Comment></Comment>
</LineItem>
<LineItem>
<Description></Description>
<Comment></Comment>
</LineItem>
</LineItems>
</PurchaseOrder>
If they _must_ be separated, then look at an Ordinal_Name / Reference
scheme. XML does this (badly) with ID and IDREF type attributes. RDF
does it in a more thought-through manner. Look at the RSS 1.0
protocol for a simple example.
In your particular case, then the XSLT is easy. However it's not
robust, because the ordering of the <LineItems> collection is not
reliable against being re-ordered. It would be much improved by some
form of "item number" attribute on each, then referring to that.

If you're stuck with the DTD as it stands, then investigate the
count() and position() functions within XSLT.
Jul 20 '05 #2
In article <d2**************************@posting.google.com >, Just Curious wrote:
Hello,

I have a following situation..
XML Document contains
<PurchaseOrder>
<LineItems>
<LineItem>
<Description></Description>
</LineItem>
<LineItem>
<Description></Description>
</LineItem>
</LineItems>
<Comments>
<Comment>
<NumberInCollection>1</NumberInCollection>
</Comment>
<Comment>
<NumberInCollection>2</NumberInCollection>
</Comment>
</Comments>
</PurchaseOrder>
When I am looping through Each Line Item using XSLT - I need to also
get corresponding comment for that line item - I have
NumberInCollection which ties with appropriate LineItem but I dont
know how to get this number when I am looping through Each LineItem.


If I correctly understand the description, in the for-each on LineItem
elements you can use

<xsl:variable name="pos" select="position()"/>

to get the position of the current LineItem element being processed
by the for-each and use the XPATH expression

../following-sibling::Comments/Comment[NumberInCollection=$pos]

to get the corresponding Comment element.
Jul 20 '05 #3
Thank you that did it!

I am hoping that xslt does processing of XML file in a linear fashion
- meaning - while looping for:each - LineItem 1 gets processeed first,
LineItem 2 gets processed second and so forth from top down

Thank you again!
ag*****@earl-grey.cloud9.net (A. Bolmarcich) wrote in message news:<slrncbuk2s.t6r.ag*****@earl-grey.cloud9.net>...
In article <d2**************************@posting.google.com >, Just Curious wrote:
Hello,

I have a following situation..
XML Document contains
<PurchaseOrder>
<LineItems>
<LineItem>
<Description></Description>
</LineItem>
<LineItem>
<Description></Description>
</LineItem>
</LineItems>
<Comments>
<Comment>
<NumberInCollection>1</NumberInCollection>
</Comment>
<Comment>
<NumberInCollection>2</NumberInCollection>
</Comment>
</Comments>
</PurchaseOrder>
When I am looping through Each Line Item using XSLT - I need to also
get corresponding comment for that line item - I have
NumberInCollection which ties with appropriate LineItem but I dont
know how to get this number when I am looping through Each LineItem.


If I correctly understand the description, in the for-each on LineItem
elements you can use

<xsl:variable name="pos" select="position()"/>

to get the position of the current LineItem element being processed
by the for-each and use the XPATH expression

../following-sibling::Comments/Comment[NumberInCollection=$pos]

to get the corresponding Comment element.

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ringo Langly | last post by:
Hi all, I'm a seasoned web programmer, but I've never touched XSLT. It's always been one of those acronyms I've never needed to educate myself on. Now... we're working with a web content...
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
3
by: Ian Roddis | last post by:
Hello, I want to embed SQL type queries within an XML data record. The XML looks something like this: <DISPLAYPAGE> <FIELD NAME="SERVER" TYPE="DROPDOWN"> <OPTION>1<OPTION> <OPTION>2<OPTION>...
0
by: DAnne | last post by:
Hi, I'm very new to xslt and this is my first time posting to a Forum so please forgive me if I transgress any protocols. I have to do a tally report. This report is divided up into sections....
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
15
by: Jeff Uchtman | last post by:
Can I draw from 2 XML sources, the structure is exactly the same execpt for data contained into 1 xslt using math to add some structrure, and displaying others as node 1 and node 2? This data is...
2
by: MichaelRKramer | last post by:
Hi, I'm new to dotnet 2.0, but I'm an expert in asp 3 or classic asp. Most of my sites are all done with XSLT and ASP which basically writes XMLs. Now I'm reading about the new cool stuff in...
14
by: Lee | last post by:
I have a xml file, here is sample part: <?xml version="1.0" encoding="UTF-8"?> <ProducsList> <Product id="1"> <SpecList> <Spec> <SpecLabel>Height</SpecLabel> <SpecValue>10</SpecValue>...
1
by: nayijitu | last post by:
Hi, I need some thing like this. I have an XML file and it contain some elements(tag) with a proper hierarchy... In that XML a particular element <page> contain some child node element like...
2
by: astroboiii | last post by:
New to the whole xml thing and finding w3schools to be an excellent resource. Now down to my question: I have several xml files I need to parse through and grab relevant information from and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.