sith
sith

Reputation: 1

XSLT Transformation ERROR

I am very new to XML and XSLT. I am trying to "transform" an xml document using xslt. Unfortunately, this is not working correctly. I am getting the following error "Error during XSLT transformation: XSLT transformation failed." in FireFox when trying to load the xml file. Chrome just loads an empty page. Both the XML and XSLT files load in the browser independently, indicating that they are both well formed. Here is the XSL file:

<wb:stylesheet version="3.0"
xmlns:wb="http://www.w3.org/1999/XSL/Transform">

<wb:template match="/">
  <html>
  <body>
    <h2>Name: <wb:value-of select="wb:world/wb:name" /></h2>
    <p><wb:vlaue-of select="wb:world/wb:desc" /></p>
  </body>
  </html>
</wb:template>

</wb:stylesheet>

and here is the XML file:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="./world.xsl"?>
<world
xmlns:wb="http://www.w3.org/2001/XMLSchema-instance" 
wb:schemaLocation="./ world.xsd">
    <wb:name>Arizelos</wb:name>
    <wb:desc>
    </wb:desc>
    <wb:nation>
        <wb:name>Whatever</wb:name>
        <wb:map>map01.png</wb:map>
        <wb:number>1</wb:number>
        <wb:desc>Whatever</wb:desc>     
        <wb:county>
            <wb:name>Whatever</wb:name>
            <wb:size>City-State</wb:size>
            <wb:number>1</wb:number>
            <wb:desc>Whatever</wb:desc>     
            <wb:community>
                <wb:name>Test</wb:name>
                <wb:size>City</wb:size>
                <wb:number>1</wb:number>
                <wb:desc>Whatever</wb:desc>     
                <wb:profession>
                    <wb:name>Sorcerer</wb:name>
                    <wb:number>1</wb:number>
                    <wb:desc>Whatever</wb:desc>     
                    <wb:person>
                        <wb:name>Harry Potter</wb:name>
                        <wb:number>1</wb:number>
                        <wb:desc>Whatever</wb:desc>
                        <wb:charsheet>
                        </wb:charsheet>
                    </wb:person>
                </wb:profession>
            </wb:community>
        </wb:county>
    </wb:nation>
    <wb:religion>
        <wb:name>Phony</wb:name>
        <wb:desc>But aren't they all?</wb:desc>
        <wb:deity>
            <wb:name>John Doe</wb:name>
            <wb:gender>Male</wb:gender>
            <wb:desc>I never considered him divine</wb:desc>
        </wb:deity>
    </wb:religion>
</world>

Thanks in advance for any help provided :)

Upvotes: 0

Views: 10080

Answers (1)

Mathias M&#252;ller
Mathias M&#252;ller

Reputation: 22647

There are a lot of problems with your code. Let me point to some of them.

In your XSLT stylesheet,

  • you have declared a non-standard prefix for the XSLT namespace: xmlns:wb="http://www.w3.org/1999/XSL/Transform". Although you can use whatever prefix you'd like, xsl is the de facto standard for it. Everything else is simply confusing.
  • you have not declared the namespace that is present in your input XML (http://www.w3.org/2001/XMLSchema-instance).
  • On top of that it is unfortunate that you use the same prefix to denote different namespace URIs in your XML and XSLT stylesheet.
  • you refer to wb:world even if the world element does not have a namespace
  • your stylesheet is version 3.0, but your browser does support 1.0 only and XSLT 3.0 is still a working draft.
  • there is a typo: vlaue-of which should read xsl:value-of

In your input XML,

  • there is this namespace declaration: xmlns:wb="http://www.w3.org/2001/XMLSchema-instance". Again, this is a non-standard prefix - you should use xsi. However, I am not sure whether you intended to use the namespace for schema instances at all.

Stylesheet

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wb="http://www.w3.org/2001/XMLSchema-instance">

   <xsl:template match="/">
     <html>
     <body>
       <h2>Name: <xsl:value-of select="world/wb:name" /></h2>
       <p><xsl:value-of select="world/wb:desc" /></p>
     </body>
     </html>
   </xsl:template>

</xsl:stylesheet>

Output

desc is empty, so nothing is output inside p.

<html xmlns:wb="http://www.w3.org/2001/XMLSchema-instance">
   <body>
      <h2>Name: Arizelos</h2>
      <p>

      </p>
   </body>
</html>

Upvotes: 2

Related Questions