XSL with multiple levels
I'm rather new to XSL, and was hoping that someone could help me with the following problem:
I have an XML file that describes various items for a computer store, things like hard drives, optical drives, network cards, etc. Each item has the same attribute list, and are grouped under elements such as <hard_disk>, <video_card>, etc. But in some instances, I have further sub-categorized items under their respective manufacturer, if a given company makes more than one item. For example, for video cards, let's say I have brand_s and brand_t. Brand_s only makes one type of video card, so I put that directly under the <video_card> element. But brand_t makes two types of video cards, so I create a new element called <brand_t_vid_card> and below that I have both of the video cards made by brand_t, such as <video_card_type_1> and <video_card_type_2>. Now, I want to use an XSL to translate this XML file into one large HTML file, listing all of the different components, but I run into a problem when I use a simple <xsl:for-each select="component/*/*/*"> statement, since this will only traverse down 3 levels from the <component> element, but in some cases (as noted above), I'll need to traverse further down to the next element. I'm sure there is an easy way to do this, but I have only limited knowledge of XSL, and I would rather not have to restructure the entire XML file so that it works with my single for-each statement. If anyone can make sense of what I'm talking about, I would greatly appreciate an answer. Below is an example of my XML file to further make my question more clear. Thanks in advance!
<component> <device> <hard_disk> <brand_x_hard_disk manufacturer="x"> <image>blah</image> <description> information about brand x hard disk </description> </brand_x_hard_disk> <brand_y_hard_disk manufacturer="y"> <image>blah</image> <description> information about brand y hard disk </description> </brand_y_hard_disk> </hard_disk> </device> <card> <video_card> <brand_s_vid_card manufacturer="s"> <image>blah</image> <description> information about brand s video card </description> </brand_s_vid_card> <brand_t_vid_card> <video_card_type_1 manufacturer="t"> <image>blah</image> <description> information about brand s video card </description> </video_card_type_1> <video_card_type_2 manufacturer="t"> <image>blah</image> <description> information about brand s video card </description> </video_card_type_2> </brand_t_vid_card> </video_card> </card> </component>
MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format