1

I've been having problems getting my XSLT file to get its XSLT functions to display, and after a bit of trial and error/debugging with Blueprint, it appears my problem has to do with my namespacing and (possibly) my XSD file. I've spent an hour with my professor trying to find the bug/problem, but to no avail.

XML File

<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet type="text/xsl" href="movies.xsl"?>

<movieRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns="http://www.example.com/comicbooks/movies/ns"
           xsi:schemaLocation="http://www.example.com/comicbooks/movies/ns movies.xsd">    

    <movie>

        <movieTitle>Captain America: Civil War</movieTitle>
        <genre>Action, Adventure, Sci-Fi</genre>
        <rating>8.13</rating>
        <length>147 min</length>
        <releaseDate>May 6th, 2016</releaseDate>

     </movie>

</movieRoot>

XSD File

<?xml version="1.0" encoding="UTF-8" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="http://www.example.com/comicbooks/movies/ns"
           targetNamespace="http://www.example.com/comicbooks/movies/ns">

    <xs:element name="movieRoot">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="movie" minOccurs="1" maxOccurs="unbounded" >
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="movieTitle" type="xs:string" />
                            <xs:element name="genre" type="xs:string" />
                            <xs:element name="rating" type="xs:string" />
                            <xs:element name="length" type="xs:string" />
                            <xs:element name="releaseDate" type="xs:string" />
                       </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
     </xs:element>

</xs:schema>

XSLT File

<?xml version="1.0" encoding="UTF-8" ?>

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


    <xsl:template match="/">

        <html>
        <head>
            <link rel="stylesheet" type="text/css" href="movies.css" />
        </head>

        <body>

            <h1><xsl:value-of select= "movieRoot/movie/releaseDate" /></h1>

        </body>
        </html>


     </xsl:template>

</xsl:stylesheet>
kjhughes
  • 106,133
  • 27
  • 181
  • 240
Tim Bob
  • 15
  • 1
  • 5

1 Answers1

1

Your XSLT isn't taking into account the default namespace of your XML.

  1. Declare a namespace prefix on your xsl:stylesheet element:

    xmlns:ns="http://www.example.com/comicbooks/movies/ns"
    
  2. And change your xsl:value-of to use the newly defined namespace prefix:

    <xsl:value-of select= "ns:movieRoot/ns:movie/ns:releaseDate" />
    

Then your XML will be rendered via your XSLT to show the date as an h1.

Notes:

  • An XSD doesn't come into play for displaying HTML transformed from XML.
  • Chrome will not load locally originating XSLT due to security concerns. Firefox will.
  • See also XSLT not working in web browser
Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240