Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XSLT无法在web浏览器中显示转换后的XML_Xml_Xslt_Xsd - Fatal编程技术网

XSLT无法在web浏览器中显示转换后的XML

XSLT无法在web浏览器中显示转换后的XML,xml,xslt,xsd,Xml,Xslt,Xsd,我在获取XSLT文件以显示其XSLT函数时遇到了问题,在使用Blueprint进行了一些尝试和错误/调试之后,我的问题似乎与名称空间和(可能)XSD文件有关。我和我的教授花了一个小时试图找出这个错误/问题,但没有结果 XML文件 <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="movies.xsl"?> <movieRoot xmlns:xsi="http

我在获取XSLT文件以显示其XSLT函数时遇到了问题,在使用Blueprint进行了一些尝试和错误/调试之后,我的问题似乎与名称空间和(可能)XSD文件有关。我和我的教授花了一个小时试图找出这个错误/问题,但没有结果

XML文件

<?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>
<?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>
<?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>

美国队长:内战
动作、冒险、科幻
8.13
147分钟
2016年5月6日
XSD文件

<?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>
<?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>
<?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>

XSLT文件

<?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>
<?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>
<?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>

XSLT没有考虑XML的默认名称空间。

  • xsl:stylesheet
    元素上声明名称空间前缀:

    xmlns:ns="http://www.example.com/comicbooks/movies/ns"
    
  • 并将的
    xsl:value更改为使用新定义的名称空间
    前缀:

    
    
  • 然后,XML将通过XSLT呈现,以
    h1
    形式显示日期

    注释

    • XSD不能用于显示从XML转换而来的HTML
    • 出于安全考虑,Chrome不会加载本地生成的XSLT。 Firefox会的
    • 另见

    请不要问同一个问题两次!对这就成功了,非常感谢。