0
untitled-2.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xml" href = "untitled-3.xsl" version="2.0"?>
<catalog>
  <cd>
    <title>abc</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Hide your hesdsdart</title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
    <company>CBS Records</company>
    <price>9.90</price>
    <year>1988</year>
  </cd>
  <cd>
    <title>Unchain my heart</title>
    <artist>Joe Cocker</artist>
    <country>USA</country>
    <company>EMI</company>
    <price>8.20</price>
    <year>1987</year>
  </cd>
</catalog>

untitled-3.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html> 
<body>
  <h2>My CD Collection</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th style="text-align:left">Title</th>
      <th style="text-align:left">Artist</th>
    </tr>
    <xsl:for-each select="catalog/cd">
    <tr>
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="artist"/></td>
    </tr>
    </xsl:for-each>
  </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

They do not display anything. Do I have to download something to get these two to link together? I copy and pasted them from w3. I tried a few of my own and didn't get any results either. I'm having trouble finding how to get them to work, I've tried a lot of online sources, most people seem to write the code and it just works. I feel like I have to download some program to run it on or something?

  • Why not use php to read the XML file as a `$xmlfile = new SimpleXMLElement($somestring)` then parse the file with something like, example: `$title = $xmlfile->cd->title`? Then build your HTML page using the php variables you parse from the XML file. – dale landry Nov 02 '20 at 23:17
  • If we're going that route I wouldn't write any xml in the first place – Jake Thorson Nov 02 '20 at 23:18
  • In JS add a new XMLHttpRequest, then `xhttp.open("GET", "untitled-2.xml", true);`, then create a variable `var xmlDoc = xml.requestXML;` do a standard incremental for loop on your `xmlDoc.getElementsByTagName('cd').length` then define and create newElement for UL and LI, append your li with the values of CD tags children, so for title it would be => `xmlDoc.getElementsByTagName("title")[i].childNodes[0].nodeValue;` and so forth, then append the UL and display in HTML... – dale landry Nov 03 '20 at 00:27

0 Answers0