Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to put links in an HTML-table from an xml-file...?

Status
Not open for further replies.

claesbas

Technical User
Aug 14, 2005
1
SE
Hi,
I'm completely new to xml, but when I found something about it, it looked like it would be a great thing to use.
However, I've stumbled on some problems - so I hope someone can help me out. It's probably very simple, but I haven't found enough info to sort it out on my own...

I have an html-file which contains a table. I've been able to change this, so I can now make a table which collects it's data from an xml-file. I also use a css-file for the layout, but I guess that's now important...

This is where I bite the dust:
In some fields in this table, I want clickable text links or image links to other pages or to other websites - but whatever I try with xlink (which I found out should be the thing to use...), the table only shows the thead - and nothing of the actual data from the xml-file, which otherwise shows up in the tbody area.
Is it enough with the html-document and the xml-file (and the css-file) - or would I need more to get the links working...?
Any ideas about what the most common rookie-faults are? I've searched for examples which I could learn from, but I've only found descriptions which claim it should work - and no examples to prove it. Could someone who knows more about this than I, put together a very simple example of what's needed to make this work...?
 
If I understand correctly you have an xml file that contains a list of links and you want these links to display properly in html format.

If this is so try using a xls stylesheet.

Extract from xml

Code:
    <Item>
      <Display>MyFiles</Display>
      <Target>myfile.htm</Target>
    </Item>
    <Item>
      <Display>mysecondfile.htm</Display>      
    </Item>

Extract from stylesheet

Code:
<!-- Define the template for the item element -->
<xsl:template match="Item">

    <ul>
      <xsl:element name="a">
        <xsl:if test="string(Target)">
          <xsl:attribute name="href">
            <xsl:value-of select="Target"/>
          </xsl:attribute>
        </xsl:if>
        <xsl:value-of select="Display"/>
      </xsl:element>
    </ul>

</xsl:template>

The code only provides the href attribute to the anchor element if the target element is completed in the xml data.
 
The code looks a little confusing, the second <item> element in the xml will only generate an anchor element in the html with a display of mysecondfile.htm but won't provide a link because the target is omitted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top