XML, XSL, XML Schema

817 Views Asked by At

I need help with XSL and XML Schema.
This is XML file:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="spellstyle.xsl"?>
<spells xmlns="spels.xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="spellsschema.xsd">
<spell category="fire" cooldown="18" manacost="100">
    <name>Fire Breath</name>
    <image id="FireBreath"/>
    <discription>Some text</discription>
    <category>Fire</category>
    <cooldown>18</cooldown>
    <manacost>100</manacost>
</spell>
</spells>

This is XML Schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"    targetNamespace="spells.xml" elementFormDefault="qualified">
<xs:element name="spells">
<xs:complexType>
    <xs:sequence>
        <xs:element name="spell">
        <xs:attribute name="category" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:pattern value="fire|water|air|earth"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="cooldown" type="xs:duration" use="required"/>
        <xs:attribute name="manacost" type="xs:decimal" use="required"/>
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="name" type="xs:string"/>
                    <xs:element name="image"/>
                    <xs:element name="discription" type="xs:string"/>
                    <xs:element name="category" type="xs:string"/>
                    <xs:element name="cooldown" type="xs:duration"/>
                    <xs:element name="manacost" type="xs:decimal"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

This is XSL:

<?xml version="1.0" encoding="utf-8"?>
<!-- DWXMLSource="spells.xml" -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="/">
  <xsl:for-each select="spells/spell">
    <xsl:value-of select="discription"/>
  </xsl:for-each>
   </xsl:template>
</xsl:stylesheet>    

The thing is when I aply my XSL file, XML stop showing at all. And I think my XML Schema is not working correctly either. My restrictions are also ignored.
What do I do?

1

There are 1 best solutions below

2
On

xsi:schemaLocation="spellsschema.xsd" is wrong, you need to put a pair of namespace uri and location uri in there: xsi:schemaLocation="spells.xml spellsschema.xsd".