XML and XSL

Discussion in 'XML' started by OleHaahr@gmail.com, Jan 17, 2006.

  1. Guest

    Hi !

    I am learning XML and XSL, and i need a hint. I have the following
    XML-file:

    <CATALOG>
    <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <TRACK>
    <ID>1/</ID>
    <NAME>Track bla bla</NAME>
    </TRACK>
    <TRACK>
    <ID>2/</ID>
    <NAME>Track bla bla bla</NAME>
    </TRACK>
    </CD>
    <CD>
    <TITLE>Hide your heart</TITLE>
    <ARTIST>Bonnie Tylor</ARTIST>
    <TRACK>
    <ID>1/</ID>
    <NAME>bla bla Track</NAME>
    </TRACK>
    <TRACK>
    <ID>2/</ID>
    <NAME>bla bla bla Track</NAME>
    </TRACK>
    </CD>
    </CATALOG>


    I want to make an XSL-file, to generate an output like this:

    Empire Burlesque Bob Dylan
    1 Track bla bla
    2 Track bla bla bla
    Hide your heart Bonnie Tylor
    1 bla bla Track
    2 bla bla bla Track

    etc...

    It is not a problem to make an output like this:

    Empire Burlesque Bob Dylan
    Hide your heart Bonnie Tylor

    But how can i show the tracks below the title.

    Can someone help me.

    Regards,
    Ole
    , Jan 17, 2006
    #1
    1. Advertising

  2. Ken Starks Guest

    1. Do you want XHTML or some other format such as plain text?
    2. If you are designing the XML yourself, you (almost certainly)
    don't need the 'ID' sub-element of a Track.
    If the ID is always unique for a track, it would be better as an
    attribute:

    <TRACK ID="1">
    ...
    </TRACK>

    If the ID is just an ordinal number, ie it always starts at 1 and
    increases by 1 for each track, you don't need it at all.


    3. Its up to you what you map the list of tracks onto. It could be
    a numbered (enumerated) list, a description list, or even a table.

    Whichever, the basic idea in XSLT will be the same:

    a. TEMPLATE for CD
    ------------------
    Do the Title and Artist
    Do the header part of the list or table
    ...Apply templates
    Do the footer part of the list or table

    b. TEMPLATE for TRACK
    ---------------------
    Do a single item of the list, or row of the table

    I'll leave the actual code for you.


    4. As a further exercise, how will your XSLT behave if presented with
    a CATALOG that include a compilation albums, where Tracks can have their
    own ARTIST>

    <CD>
    <TITLE>Compilation</TITLE>
    <ARTIST>Various</ARTIST>

    <TRACK>
    <ID>1/</ID>
    <ARTIST>Dylan</ARTIST>
    <NAME>Track bla bla</NAME>
    </TRACK>

    <TRACK>
    <ARTIST>Bonnie Tylor</ARTIST>
    <ID>2/</ID>
    <NAME>Track bla bla bla</NAME>
    </TRACK>
    </CD>


    wrote:

    > Hi !
    >
    > I am learning XML and XSL, and i need a hint. I have the following
    > XML-file:
    >
    > <CATALOG>
    > <CD>
    > <TITLE>Empire Burlesque</TITLE>
    > <ARTIST>Bob Dylan</ARTIST>
    > <TRACK>
    > <ID>1/</ID>
    > <NAME>Track bla bla</NAME>
    > </TRACK>
    > <TRACK>
    > <ID>2/</ID>
    > <NAME>Track bla bla bla</NAME>
    > </TRACK>
    > </CD>
    > <CD>
    > <TITLE>Hide your heart</TITLE>
    > <ARTIST>Bonnie Tylor</ARTIST>
    > <TRACK>
    > <ID>1/</ID>
    > <NAME>bla bla Track</NAME>
    > </TRACK>
    > <TRACK>
    > <ID>2/</ID>
    > <NAME>bla bla bla Track</NAME>
    > </TRACK>
    > </CD>
    > </CATALOG>
    >
    >
    > I want to make an XSL-file, to generate an output like this:
    >
    > Empire Burlesque Bob Dylan
    > 1 Track bla bla
    > 2 Track bla bla bla
    > Hide your heart Bonnie Tylor
    > 1 bla bla Track
    > 2 bla bla bla Track
    >
    > etc...
    Ken Starks, Jan 17, 2006
    #2
    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. Karsten Weinert
    Replies:
    3
    Views:
    991
    Karsten Weinert
    Jul 5, 2004
  2. Vijay singh
    Replies:
    1
    Views:
    429
    Martin Honnen
    Nov 4, 2004
  3. David Carlisle

    xsl:import and xsl:apply_import

    David Carlisle, Dec 16, 2004, in forum: XML
    Replies:
    5
    Views:
    485
    Shiju Rajan
    Dec 16, 2004
  4. Replies:
    1
    Views:
    3,589
    A. Bolmarcich
    May 27, 2005
  5. enggr
    Replies:
    0
    Views:
    1,620
    enggr
    Jun 30, 2010
Loading...

Share This Page