XSLT-Prozessor-Fehler?
Zul
- php
Hi Forum,
Ich verzweifle im Moment an diesem Code:
<?xml
$xml = new DOMDocument;
$xml->loadXML('<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="src/config.xsl"?>
<!DOCTYPE config PUBLIC "-//ICG//DTD CONFIG 1.0//EN" "src/config.dtd">
<config xmlns="http://imbacms.org/config">
<group name="lang">
<value name="standart" value="de"/>
</group>
</config>
');
$xsl = new DOMDocument;
$xsl->loadXML('<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="html">
<xsl:output method="xml" indent="yes" encoding="utf-8" media-type="application/xhtml+xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<xsl:template match="/">
<html>
<head>
<title>Config</title>
<link rel="stylesheet" type="text/css" href="src/config.css"/>
</head>
<body>
<h1>Config</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="group">
<h2>
<xsl:value-of select="@name"/>
</h2>
<dl>
<xsl:apply-templates/>
</dl>
</xsl:template>
<xsl:template match="value">
<dt>
<xsl:value-of select="@name"/>
</dt>
<dd>
<xsl:value-of select="@value"/>
</dd>
</xsl:template>
</xsl:stylesheet>');
$xsltprocessor = new XSLTProcessor();
$xsltprocessor->importStylesheet($xsl);
header('content-type: text/plain');
echo $xsltprocessor->transformToXML($xml);
?>
Eigentlich müsste er diese Ausgabe erzeugen:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Config</title>
<link rel="stylesheet" type="text/css" href="src/config.css" />
</head>
<body>
<h1>Config</h1>
<h2>lang</h2>
<dl>
<dt>standart</dt>
<dd>de</dd>
</dl>
</body>
</html>
Ich erhalte leider immer nur diese:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Config</title>
<link rel="stylesheet" type="text/css" href="src/config.css" />
</head>
<body><h1>Config</h1>
</body>
</html>
Was mache ich falsch? Ist mein XSL-Dokument fehlerhaft, rufe ich den XSLT-Prozessor falsch auf?
Mfg Zul
Hallo Zul,
Was mache ich falsch? Ist mein XSL-Dokument fehlerhaft, rufe ich den XSLT-Prozessor falsch auf?
Beachte den Namensraum aus dem XML-Dokument auch im XSLT-Stylesheet (hier als config-Prefix verwendet):
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" xmlns:config="http://imbacms.org/config" exclude-result-prefixes="html config">
<xsl:output method="xml" indent="yes" encoding="utf-8" media-type="application/xhtml+xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<xsl:template match="/">
<html>
<head>
<title>Config</title>
<link rel="stylesheet" type="text/css" href="src/config.css"/>
</head>
<body>
<h1>Config</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="config:group">
<h2>
<xsl:value-of select="@name"/>
</h2>
<dl>
<xsl:apply-templates/>
</dl>
</xsl:template>
<xsl:template match="config:value">
<dt>
<xsl:value-of select="@name"/>
</dt>
<dd>
<xsl:value-of select="@value"/>
</dd>
</xsl:template>
</xsl:stylesheet>
Die PI xml-stylesheet kann übrigens entfallen.
Grüße,
Thomas
Hi ThomasM,
Hallo Zul,
Was mache ich falsch? Ist mein XSL-Dokument fehlerhaft, rufe ich den XSLT-Prozessor falsch auf?
Beachte den Namensraum aus dem XML-Dokument auch im XSLT-Stylesheet (hier als config-Prefix verwendet):
Danke! Jetzt geht's.
Die PI xml-stylesheet kann übrigens entfallen.
Richtig im Moment brauch ich sie nicht, ich lasse sie aber trozdem drinne weil das XML-Dokumen ist noch in einer Datei abgespeichert, und diese kann ich so auch mit dem Browser öffnen.
Mfg Zul