Display by category...

Discussion in 'XML' started by Zhou Lei, Mar 2, 2005.

  1. Zhou Lei

    Zhou Lei Guest

    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.
     
    Zhou Lei, Mar 2, 2005
    #1
    1. Advertising

  2. Zhou Lei

    Joris Gillis Guest

    Tempore 09:16:52, die Wednesday 02 March 2005 AD, hinc in foro {comp.text.xml} scripsit Zhou Lei <>:

    > 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" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput 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-view.cgi?userid=38041)
    Spread the wiki (http://www.wikipedia.org)
     
    Joris Gillis, Mar 2, 2005
    #2
    1. Advertising

  3. Zhou Lei

    Zhou Lei Guest

    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...
     
    Zhou Lei, Mar 3, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Hendryx

    Infinite Product Category Display

    Paul Hendryx, Apr 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    362
    Paul Hendryx
    Apr 9, 2004
  2. Replies:
    4
    Views:
    401
  3. Li Ming
    Replies:
    4
    Views:
    463
    Li Ming
    Mar 1, 2005
  4. Steve H
    Replies:
    1
    Views:
    366
    Howard Hinnant
    Apr 19, 2005
  5. lavey
    Replies:
    3
    Views:
    281
Loading...

Share This Page