XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 15th, 2004, 04:09 AM
Robin Bailey Robin Bailey is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: South East of England
Posts: 11 Robin Bailey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Category Headings in XSL

Hi,

I have a list of items which are in categories and some in subcategories too. In the XML these are contained in the XML of each item (see below). In the XSL file what do I need to do to get the categories and subcategories to be displayed as headings? Obvious I want only one heading for each category/subcategory.

<ITEM_DETAILS>
<ID>128</ID>
<DESC>30mm x 2mm</DESC>
<CAT_DESC>Washers</CAT_DESC>
<CAB_PAGE>
<SUB_CATEGORIES>Brass<SUB_CATEGORIES/>
</CAB_PAGE>
</ITEM_DETAILS>
<ITEM_DETAILS>
<ID>131<ID>
<DESC>35mm x 2mm</DESC>
<CAT_DESC>Washers</CAT_DESC>
<CAB_PAGE>
<SUB_CATEGORIES>Brass<SUB_CATEGORIES/>
</CAB_PAGE>
</ITEM_DETAILS>
<ITEM_DETAILS>
<ID>131<ID>
<DESC>20mm</DESC>
<CAT_DESC>Washers</CAT_DESC>
<CAB_PAGE>
<SUB_CATEGORIES>Steel<SUB_CATEGORIES/>
</CAB_PAGE>
</ITEM_DETAILS>
<ITEM_DETAILS>
<ID>131<ID>
<DESC>65mm</DESC>
<CAT_DESC>Nuts</CAT_DESC>
<CAB_PAGE>
<SUB_CATEGORIES>Brass<SUB_CATEGORIES/>
</CAB_PAGE>
</ITEM_DETAILS>

Reply With Quote
  #2  
Old January 15th, 2004, 09:19 PM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 282 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 2 h 30 m 42 sec
Reputation Power: 6
What you are trying to do is probably best handled using the
Muenchian Method. See Jeni Tennison's explanation at

http://www.jenitennison.com/xslt/gr.../muenchian.html

Here is a rough example of this technique based on your
requirements.

XML source:

<FPM>
<ITEM_DETAILS>
<ID>128</ID>
<DESC>30mm x 2mm</DESC>
<CAT_DESC>Washers</CAT_DESC>
<CAB_PAGE>
<SUB_CATEGORIES>Brass</SUB_CATEGORIES>
</CAB_PAGE>
</ITEM_DETAILS>
<ITEM_DETAILS>
<ID>131</ID>
<DESC>35mm x 2mm</DESC>
<CAT_DESC>Washers</CAT_DESC>
<CAB_PAGE>
<SUB_CATEGORIES>Brass</SUB_CATEGORIES>
</CAB_PAGE>
</ITEM_DETAILS>
<ITEM_DETAILS>
<ID>132</ID>
<DESC>20mm</DESC>
<CAT_DESC>Washers</CAT_DESC>
<CAB_PAGE>
<SUB_CATEGORIES>Steel</SUB_CATEGORIES>
</CAB_PAGE>
</ITEM_DETAILS>
<ITEM_DETAILS>
<ID>133</ID>
<DESC>65mm</DESC>
<CAT_DESC>Nuts</CAT_DESC>
<CAB_PAGE>
<SUB_CATEGORIES>Brass</SUB_CATEGORIES>
</CAB_PAGE>
</ITEM_DETAILS>
</FPM>


XSL source:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xslutput method="html" indent="yes" standalone="yes"
omit-xml-declaration="no" encoding="UTF-8"/>

<xsl:key name="items" match="ITEM_DETAILS" use="concat(CAT_DESC, CAB_PAGE/SUB_CATEGORIES)" />

<xsl:template match="FPM">
<html>
<body>

<xsl:for-each select="ITEM_DETAILS[count(. | key('items', concat(CAT_DESC,CAB_PAGE/SUB_CATEGORIES))[1]) = 1]">
<xsl:sort select="CAT_DESC" />
<h2><xsl:value-of select="CAT_DESC" /> - <xsl:value-of select="CAB_PAGE/SUB_CATEGORIES"/></h2>
<xsl:for-each select="key('items', concat(CAT_DESC,CAB_PAGE/SUB_CATEGORIES))">
<xsl:sort select="CAB_PAGE/SUB_CATEGORIES/ID" />
<p><xsl:value-of select="ID"/>: <xsl:value-of select="DESC"/></p>
</xsl:for-each>
</xsl:for-each>

</body>
</html>

</xsl:template>

</xsl:stylesheet>


- Finnbarr

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Category Headings in XSL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT