473,379 Members | 1,379 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,379 software developers and data experts.

xsl stylesheet problem selecting specific nodes

Ok, I'm sure the answer is right in front of me, but I can't see if
for the life of me. Here's my xml document:

<price_guide>
<group><name>Wacky Widgets</name>
<product>
<product_id>1</product_id>
<description>Widget 1</description>
<sell>
<quantity>500</quantity>
<price>25.50</qunatity>
</sell>
<sell>
<quantity>1000</quantity>
<price>34.20</price>
</sell>
</product>
<!-- Multiple producst here-->
</group>
<group><name>Cool Computers</name>
<product>
<product_id>2</product_id>
<description>Computer 1</description>
<sell>
<quantity>500</quantity>
<price>50.43</price>
</sell>
<sell>
<quantity>1000</quantity>
<price>83.10</price>
</sell>
<sell>
<quantity>2500</quantity>
<price>160.76</price>
</sell>
</product>
</group>
</price_guide>

Now, I want a stylesheet that takes each group and puts it in a
separate HTML table with the Name as an <h2header and Product ID,
Description, and each quantity as a Column header. Apparently there
are too many "for-each" loops in this for my small brain to handle.
What I'm getting is that is makes a table for each group containing
every product in every group, rather than every product in that
particular group. What do I need to do this without having to say /
product_guide/group[n]/product every time?

Apr 5 '07 #1
1 1553
do******@gmail.com wrote:
Now, I want a stylesheet that takes each group and puts it in a
separate HTML table with the Name as an <h2header and Product ID,
Description, and each quantity as a Column header. Apparently there
are too many "for-each" loops in this for my small brain to handle.
For-each loops should be a last resort. It's almost always simpler, and
easier to maintain, if you just code templates and apply-template
requests, and let XSLT do the looping.

Root template: match "/", and apply-templates with select="group"

Group template: match "group", and do the processing for a group: get
the name and render it as an h2, start the table and apply-templates
against "product"; then end the table.

Product template: match "product", start a tr, process the contents into
tds by further apply-templates, end the tr.

In other words, let XSLT keep track of context, while you focus on
processing one node at a time.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Apr 5 '07 #2

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

Similar topics

2
by: Razvan | last post by:
Hi, Can an XSL stylesheet have 2 root templates ? How about 2 templates that match the same set of nodes ? Which one gets executed ? Regards,
2
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: August 28, 2002 Version: 1.15 URL: http://css.nu/faq/ciwas-aFAQ.html...
0
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: April 10, 2003 Version: 1.16 URL: http://css.nu/faq/ciwas-aFAQ.html Maintainer:...
1
by: Nancy Shelley | last post by:
Hi all: I am building a navigation menu using telerik's rad treeview I am able to build the outer menu but not the children. How do I select the child nodes (item) from within the loop? Any...
4
by: JoKur | last post by:
I'm currently using a context menu to allow the user to add, rename and delete nodes in a treeview control. When a node is added we give it a bogus name ("NewNode") and invoke the add method. We...
2
by: Marc Jennings | last post by:
Hi there, I have been given a rather poor schema for an XML file in the following format : ><item> > <key>ProductCode</key> > <value>1234-5678</value> > <key>Description</key> >...
2
by: Tymbow | last post by:
I'm building a web application that is analogous to the Windows XP file explorer in function. The left column contains a TreeView, and the right column a DataGrid populated by selecting TreeView...
7
by: PatrickRThomas | last post by:
I need help selecting nodes while excluding some of them. Here's an example of XML: <my_xml> <all_items> <item> <key>1</key> <name>Item 1</name> </item> <item>
6
by: dragze | last post by:
Hi, right i have a menu box wich allows the user to change what stylesheet the website uses. Now this all works just the way it shud in FF, but not in safari or IE, when u select ur option from the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.