First off, I'm new to XSLT, so excuse me if this a dumb question.
I'm trying to embed XHTML code from a XML file and I'm wondering why PHP's XSLT doesn't indent it correctly.
So, this stylesheet:
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="iso-8859-1"
doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
media-type="application/xhtml+xml"
omit-xml-declaration="yes" />
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<body>
<xsl:apply-templates select="*/content/text" />
</body>
</html>
</xsl:template>
<xsl:template match="*/content/text">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="*/content/text//*">
<xsl:element name="{local-name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="node()" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
applied to this document:
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
<root>
<content>
<text><xhtml:form action="" method="post"><xhtml:input type="text" id="foo" name="bar" /><input type="submit" name="submit" /></xhtml:form></text>
</content>
<content>
<text>
<xhtml:form action="" method="post">
<xhtml:input type="text" id="foo" name="bar" />
<xhtml:input type="submit" name="submit" />
</xhtml:form>
</text>
</content>
</root>
produces this output:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<body><form action="" method="post"><input type="text" id="foo" name="bar"/><input type="submit" name="submit"/></form>
<form action="" method="post">
<input type="text" id="foo" name="bar"/>
<input type="submit" name="submit"/>
</form>
</body>
</html>
If I set "indent" to "no", then it produces this output:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><body><form action="" method="post"><input type="text" id="foo" name="bar"/><input type="submit" name="submit"/></form>
<form action="" method="post">
<input type="text" id="foo" name="bar"/>
<input type="submit" name="submit"/>
</form>
</body></html>
Is it possible to indent the XHTML code from the XML file so that it fits the rest of the (XHTML) document, and if so, how?
Any help appreciated!