Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xml error xsl stylesheet

Tags:

php

xml

xslt

I have the following errors

error on line 1 at column 40: Extra content at the end of the document

When try to output xml file:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="producers.xsl"?>
<producers>
  <producer>
    <id>8</id>
    <name>Emåmejeriet</name>
    <street>Grenvägen 1-3</street>
    <postal>577 39</postal>
    <city>Hultsfred</city>
    <weburl>http://www.emamejerie3t.se</weburl>
  </producer>
</producers>

I have validated the xml and I get no errors. the xsl template looks like this

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <head><title>Producenter</title></head>
    <body>
        <p>
            <xsl:value-of select="producers/producer/id"/>
        </p>
    </body>
</xsl:template>
</xsl:stylesheet>

What am I missing?

like image 863
user1729425 Avatar asked Feb 06 '26 01:02

user1729425


1 Answers

Html tag missing. XML must have a one root element, (you have two - head and body) Error persists after string

<head><title>Producenter</title></head>

when the validator find a second root element (body).

just add root html tag

<?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><title>Producenter</title></head>
    <body>
        <p>
            <xsl:value-of select="producers/producer/id"/>
        </p>
    </body>
</html>
</xsl:template>
</xsl:stylesheet>
like image 125
Sergey Karasev Avatar answered Feb 08 '26 15:02

Sergey Karasev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!