Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML and XSL

Reply
Thread Tools

XML and XSL

 
 
OleHaahr@gmail.com
Guest
Posts: n/a
 
      01-17-2006
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

 
Reply With Quote
 
 
 
 
Ken Starks
Guest
Posts: n/a
 
      01-17-2006
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>


http://www.velocityreviews.com/forums/(E-Mail Removed) 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...


 
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
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
xsl:import and xsl:apply_import David Carlisle XML 5 12-16-2004 02:44 PM
XSLT question related to <xsl:template> and <xsl:apply-templates> Vijay singh XML 1 11-04-2004 03:42 PM
Difference between xsl:param and xsl:variable? Karsten Weinert XML 3 07-05-2004 04:58 PM
Three question which is not yet answered clearly and correct so far !! challenging question in xsl and also in xsl fo Philip Meyer XML 0 11-30-2003 04:42 PM



Advertisments