XML and XSL

O

OleHaahr

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
 
K

Ken Starks

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top