XML Document not registering XSL stylesheet?

后端 未结 1 1354
慢半拍i
慢半拍i 2021-01-27 23:56

I\'ve been trying to test-link my XML document with my XSL stylesheet, however it all it does is display the XML doc\'s information and ignores my templates, and I have no clue

相关标签:
1条回答
  • 2021-01-28 00:22

    Your xml file has a default namespace.
    You need to declare this namespace in the xsl file and use it.

    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:ns="http://www.example.com/comicbooks/movies/ns">
    


    <xsl:template match="ns:movie">
    

    Also you have a typo: ref instead of rel.

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

    After modifying the xsl file should look like this:

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:ns="http://www.example.com/comicbooks/movies/ns">
    
        <xsl:template match="/">
    
            <html>
            <link rel="stylesheet" type="text/css" href="movies.css" />
            <body>
                <xsl:apply-templates />
            </body>
            </html>
    
        </xsl:template>
    
        <xsl:template match="ns:movie">
    
            <p>Movies</p>
    
        </xsl:template>
    
    </xsl:stylesheet>
    

    Other files remain unchanged.

    0 讨论(0)
提交回复
热议问题