Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Display by category...

Reply
Thread Tools

Display by category...

 
 
Zhou Lei
Guest
Posts: n/a
 
      03-02-2005

Hello I'm posting a new article about the category. The following XML
segment was posted by Li some days ago and I'm trying to do some more work:

<shop name="myshop">
<category>
<cd type="pop">Pop music</cd>
<cd type="rock">Rock</cd>
<cd type="classical">Classical music</cd>
</category>

<welcome>Welcome to myshop</welcome>

<content>
<headline>Music CD</headline>
<location name="Address">
<cdshelf>
<disc name="CCC" cg="pop"/>
<disc name="AAA" cg="pop"/>
<disc name="EEE" cg="rock"/>
<disc name="GGG" cg="pop"/>
</cdshelf>
</location>

<location name="AnotherAddress">
<cdshelf>
<disc name="BBB" cg="classical"/>
<disc name="DDD" cg="pop"/>
<disc name="FFF" cg="classical"/>
</cdshelf>
</location>

</content>
</shop>

The desired web output:

Welcome to myshop

Music CD

Location Address:

Pop music:
1. CCC
3. AAA
4. GGG

Rock:
1. EEE

Location AnotherAddress:

Classical music:
1. BBB
2. FFF

Pop music:
1. DDD


The XML file contains 2 locations, and each location has different kinds of CDs
available (some are unavailable, for example, classical CDs are absent at
location "Address"). And the correct CDs should appear according to
its location and the category should be listed in ascendent order. Is it
possible to do it? Thank you.
 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      03-02-2005
Tempore 09:16:52, die Wednesday 02 March 2005 AD, hinc in foro {comp.text.xml} scripsit Zhou Lei <(E-Mail Removed)>:

> The XML file contains 2 locations, and each location has different kinds of CDs
> available (some are unavailable, for example, classical CDs are absent at
> location "Address"). And the correct CDs should appear according to
> its location and the category should be listed in ascendent order. Is it
> possible to do it? Thank you.
>

Once again, no problem

here's one example, using xpath rather than keys.

<xsl:stylesheet version="1.0" xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslutput indent="yes" />

<xsl:template match="category"/>

<xsl:template match="welcome | headline">
<xsl:element name="h{count(ancestor::*)}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="cdshelf">
<xsl:variable name="shelf" select="."/>
<xsl:for-each select="ancestor::shop/category/cd">
<xsl:sort/>
<xsl:if test="$shelf/disc[@cg=current()/@type]">
<h4><xsl:apply-templates/>:</h4>
<ol>
<xsl:apply-templates select="$shelf/disc[@cg=current()/@type]"/>
</ol>
</xsl:if>
</xsl:for-each>
</xsl:template>

<xsl:template match="location">
<h3>Location <xsl:value-of select="@name"/>:</h3>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="disc">
<li><xsl:value-of select="@name"/></li>
</xsl:template>

</xsl:stylesheet>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Spread the wiki (http://www.wikipedia.org)
 
Reply With Quote
 
 
 
 
Zhou Lei
Guest
Posts: n/a
 
      03-03-2005

Okay I got it. Thank you very much for your help now I can use XSLT better than
before And please help me when I have problems again...
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display byte array back to pdf and display in IE SG Java 6 01-15-2008 01:02 PM
choosing to display or not to display a checkbox in repeater control. Imran Aziz ASP .Net 4 08-11-2005 05:00 PM
mixing raw xml display w/ formated display blank101 XML 2 02-05-2005 03:10 PM
Double double display display problem problem Tom Accuosti Firefox 3 09-27-2004 10:02 PM
Display and display model Marc Twain Java 1 01-13-2004 07:05 PM



Advertisments