0

Maybe you can help me out with this issue. I have an xml file with an xsl and xsd attach to it. However, my information from xsl doesn't load at all. It only works when i link my xml file to dtd, but not with xsl. Can you guys help me out with this? Thanks in advance.

This is how my xml file looks like.

<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet type='text/xsl' href='wishlist.xsl'?>
<coins 
    xmlns="https://www.w3schools.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://student.mccinfo.net/~armatsumura/wishlist.xsd">>
   <wish_list> 
        <coin_id>SGB123</coin_id>
        <issue_date>hi</issue_date>
        <category>American</category>
        <type>Antique</type>
        <value>$2000</value>
    </wish_list>
</coins>

This is my xsd file

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://student.mccinfo.net/~armatsumura/wishlist.xsd"
  xmlns="http://student.mccinfo.net/~armatsumura/wishlist.xsd"
  elementFormDefault="qualified">  
  <xs:element name="coins">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="wish_list"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="wish_list">
    <xs:complexType>
      <xs:sequence minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="coin_id"/>
        <xs:element ref="issue_date"/>
        <xs:element ref="category"/>
        <xs:element ref="type"/>
        <xs:element ref="value"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="coin_id" type="xs:string"/>
  <xs:element name="issue_date" type="xs:string"/>
  <xs:element name="category" type="xs:string"/>
  <xs:element name="type" type="xs:string"/>
  <xs:element name="value" type="xs:string"/>
</xs:schema>

This is my XSLT

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            <head>
                <title>Wishlist</title>
                <link rel="stylesheet" href="coins.css"/>
            </head>
            <body>
                <ul>
                    <li><a href="http://student.mccinfo.net/~armatsumura/home.htm">Home</a></li>
                    <li><a href="http://student.mccinfo.net/~armatsumura/inventory.xml">Inventory</a></li>
                    <li><a href="http://student.mccinfo.net/~armatsumura/wishlist.xml">Wishlist</a></li>
                    <li><a href="http://student.mccinfo.net/~armatsumura/insurance.xml">Insurance</a></li>
                    <li><a href="http://student.mccinfo.net/~armatsumura/vendor.xml">Vendors</a></li>
                    <li><a href="mailto:armatsumura@mail.mccneb.edu">armatsumura.mail@mccneb.edu</a></li>
                </ul> 
                <center><h2>Wishlist</h2></center>
                <center><table border="1">
                    <tr bgcolor="#ffffff">
                        <th style="text-align:center">Coin ID</th>
                        <th style="text-align:center">Issue Date</th>
                        <th style="text-align:center">Category</th>
                        <th style="text-align:center">Type</th>
                        <th style="text-align:center">Value</th>
                    </tr>
                    <xsl:for-each select="coins/wish_list">
                        <tr>
                            <td><xsl:value-of select="coin_id"/></td>
                            <td><xsl:value-of select="issue_date"/></td>
                            <td><xsl:value-of select="category"/></td>
                            <td><xsl:value-of select="type"/></td>
                            <td><xsl:value-of select="value"/></td>
                        </tr>
                    </xsl:for-each>
                </table></center>
            </body>
        </html>
        
        
    </xsl:template>    
    
</xsl:stylesheet>
Andrew M
  • 21
  • 3

1 Answers1

0

A couple of things ..

If you are testing this in browser such as FireFox, then your XML needs to be compliant to the XPath 1.0 spec. You can read about that here: What browsers support Xpath 2.0?

Pursuant to the link above your declaration should look like this, note the change to the first namespace, it is now xmlns:cs. This will provide a namespace prefix. Also, you have an extra '>', might want to remove that :)

<coins 
    xmlns:cs="https://www.w3schools.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://student.mccinfo.net/~armatsumura/wishlist.xsd">

Then in your XSLT you can add the 'prefixed' namespace so that that the XSLT looks like this, again note the new line for the prefixed namespace

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:cs="https://www.w3schools.com">

Next the root selector should be /* so it will select everything under the root, you could also replace the /* with the name of the root, but that is a personal preference type of thing.

<xsl:template match="/*">

Finally, I don't think the XSD is relevant to this question, XSD is used to validate the 'correctness' of your XML file, does it contain the required elements, are the data types correct, etc; but I don't see anything like that in your XSL definition.

Let me know if this helps.

vscoder
  • 929
  • 1
  • 10
  • 25