Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Generating an HTML table with links without using data islands

Posted on 2004-09-05
6
254 Views
Last Modified: 2008-02-01
Hello!
  A number of people have asked similar questions to mine, but I find I still need help. So- here is my problem.
  I want to make an HTML table that will allow users to access a number of different related files for a number of different recordings I have.  A simplified version of my table would like like:

Filename      (WAV)     (MP3)    Text (Unicode)        Text (TIF image)       Text (JPG)   Details
Recording 1   WAV       MP3       Unicode Text           TIFF Image               JPG             Details
Recording 2   WAV       MP3       Unicode Text           TIFF Image               JPG             Details

I want each bit of text (except for the filename) to link to a file on the website, so that WAV would link (obviously) to a WAV version of the recording, and the JPG link would let users see a scanned image of accompanying text.
 
Here is the XML file that I am trying to generate this from (the first few entries, anyway):

<?xml version="1.0">
<metadata>

<item>
<filename_audio>GLSword-list.1996.01</filename_audio>
<filename_wav>GLSword-list.1996.01.wav</filename_wav>
<filename_mp3>GLSword-list.1996.01.mp3</filename_mp3>
<xml_unicode>GLSword-list.1997.01.xml</xml_unicode>
<html_unicode>GLSword-list.1997.01.htm</html_unicode>
<unicode_entries>1 - 38</unicode_entries>
<filename_image>GLSword-list.1996.01</filename_image>
<image_tif>GLSword-list.1996.01.tif</image_tif>
<image_jpg>GLSword-list.1996.01.jpg</image_jpg>
<details>GLSrecord_details.xml</details>
</item>

<item>
<filename_audio>GLSword-list.1996.02</filename_audio>
<filename_wav>GLSword-list.1996.02.wav</filename_wav>
<filename_mp3>GLSword-list.1996.02.mp3</filename_mp3>
<xml_unicode>GLSword-list.1997.01.xml</xml_unicode>
<html_unicode>GLSword-list.1997.01.htm</html_unicode>
<unicode_entries>39 - 80</unicode_entries>
<filename_image>GLSword-list.1996.02</filename_image>
<image_tif>GLSword-list.1996.02.tif</image_tif>
<image_jpg>GLSword-list.1996.02.jpg</image_jpg>
<details>GLSrecord_details.xml</details>
</item>

<item>
<filename_audio>GLSword-list.1996.03</filename_audio>
<filename_wav>GLSword-list.1996.03.wav</filename_wav>
<filename_mp3>GLSword-list.1996.03.mp3</filename_mp3>
<xml_unicode>GLSword-list.1997.01.xml</xml_unicode>
<html_unicode>GLSword-list.1997.01.htm</html_unicode>
<unicode_entries>81 - 121</unicode_entries>
<filename_image>GLSword-list.1996.03</filename_image>
<image_tif>GLSword-list.1996.03.tif</image_tif>
<image_jpg>GLSword-list.1996.03.jpg</image_jpg>
<details>GLSrecord_details.xml</details>
</item>

<item>
<filename_audio>GLSword-list.1996.04</filename_audio>
<filename_wav>GLSword-list.1996.04.wav</filename_wav>
<filename_mp3>GLSword-list.1996.04.mp3</filename_mp3>
<xml_unicode>GLSword-list.1997.01.xml</xml_unicode>
<html_unicode>GLSword-list.1997.01.htm</html_unicode>
<unicode_entries>122 - 160</unicode_entries>
<filename_image>GLSword-list.1996.04</filename_image>
<image_tif>GLSword-list.1996.04.tif</image_tif>
<image_jpg>GLSword-list.1996.04.jpg</image_jpg>
<details>GLSrecord_details.xml</details>
</item>
   
</metadata>  

So, after my table is generated, I would want the first WAV link to link to "GLSword-list.1997.01.wav" (the <filename_audio> element of the first item), the first MP3 to link to GLSword-list.1997.01.mp3, etc.

I've been able to do this with data islands, but discovered to late that browsers that aren't Windows Internet Explorer don't support data islands.

Thanks in advance for your help!
0
Comment
Question by:adulcimist
  • 4
  • 2
6 Comments
 
LVL 5

Expert Comment

by:conorj
ID: 11988475
Is this what you want?? Obviously, you will want to change the CSS styling to suit your needs, etc, etc

..............
<xsl:template match="/">
    <table>
        <thead>
            <tr>                                
                <th>Filename</th>
                <th>(WAV)</th>
                <th>(MP3)</th>
                <th>Text (Unicode)</th>
                <th>Text (TIF image)</th>
                <th>Text (JPG)</th>
                <th>Details</th>
            </tr>
        </thead>
        <tbody>
            <xsl:apply-templates select="metadata/item" />
        </tbody>
    </table>
</xsl:template>

<xsl:template match="item">
    <tr>
        <td><xsl:value-of select="filename_audio" /></td>
        <td><a href="filename_wav"><xsl:value-of select="filename_wav" /></a></td>
        <td><a href="filename_mp3"><xsl:value-of select="filename_mp3" /></a></td>
        <td><a href="html_unicode"><xsl:value-of select="html_unicode" /></a></td>
        <td><a href="image_tif"><xsl:value-of select="image_tif" /></a></td>
        <td><a href="image_jpg"><xsl:value-of select="image_jpg" /></a></td>
        <td><a href="details"><xsl:value-of select="details" /></a></td>
    </tr>
</xsl:template>
..................

rgds,
Conor.
0
 

Author Comment

by:adulcimist
ID: 11991229
Hmm...I'm afraid I'm still having trouble, but it's probably the way I'm linking your stylesheet to my document.
 Using what you typed, I made an external XSL file metadata.xsl:

<?xml version="1.0"?>

<stylesheet xmlns:xsl="http://wwww.w3.org/1999/Transform">
<xsl:template match="/">
    <table>
        <thead>
            <tr>                                
                <th>Filename</th>
                <th>(WAV)</th>
                <th>(MP3)</th>
                <th>Text (Unicode)</th>
                <th>Text (TIF image)</th>
                <th>Text (JPG)</th>
                <th>Details</th>
            </tr>
        </thead>
        <tbody>
            <xsl:apply-templates select="metadata/item" />
        </tbody>
    </table>
</xsl:template>

<xsl:template match="item">
    <tr>
        <td><xsl:value-of select="filename_audio" /></td>
        <td><a href="filename_wav"><xsl:value-of select="filename_wav"

/></a></td>
        <td><a href="filename_mp3"><xsl:value-of select="filename_mp3"

/></a></td>
        <td><a href="html_unicode"><xsl:value-of select="html_unicode"

/></a></td>
        <td><a href="image_tif"><xsl:value-of select="image_tif" /></

a></td>
        <td><a href="image_jpg"><xsl:value-of select="image_jpg" /></

a></td>
        <td><a href="details"><xsl:value-of select="details" /></a></

td>
    </tr>
</xsl:template>
</stylesheet>

And then I liked this file to my XML document by entering the line:

<?xml-stylesheet type="text/xsl" href="metadata.xsl"?>

With these changes, when I open my XML document, Internet Explorer displays only the table headers, while Netscape 7.0 and Firefox both give me:

Error loading stylesheet: Parsing an XSLT stylesheet failed.

Clearly I'm doing something wrong...
0
 

Author Comment

by:adulcimist
ID: 11991277
Addendum: After posting that, I realized that when I pasted your code into notepad, some of the lines got broken up.  That's not the problem.  I've fixed that, and still no luck.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:adulcimist
ID: 11993081
Ok- so I've gotten the stylesheet to interact properly with my xml, but when the list generates, the links don't work quite right.  right now, using

td><a href="filename_wav"><xsl:value-of select="filename_wav" /></a></td>,

the link is literally to "filename_wav" and not to the value of <filename_wav> in my XML file, which is what I need.
  Did the links reference the value properly on your computer?
0
 
LVL 5

Accepted Solution

by:
conorj earned 500 total points
ID: 11996273
OK, just spotted some typos in my original reply. All the href attributes should have curly-braces as follows:

<a href="{filename_wav}">

this is a shorthand way or writing

<a>
<xsl:attribute name="href"><xsl:value-of select="filename_wav" /></xsl:attribute>
...
</a>

rgds,
Conor.
0
 

Author Comment

by:adulcimist
ID: 11997633
Beautiful!  That's exactly what I want- the curly braces were definitely the missing bit of information that I needed.  Thanks so much!
            Patrick
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question