Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 30th, 2005, 04:42 PM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Embed XHTML code

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!

 
Old January 1st, 2006, 12:34 PM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hm, I'm still wondering if this is a namespace or white-space/CR/LF problem.

 
Old January 1st, 2006, 01:41 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The effect of indent="yes" depends on the XSLT processor you are using - the processor can ignore it completely if it wants. You'd be better off asking this question on a forum specific to the XSLT processor that you're using.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Embed image into email rpkbuddhi PHP How-To 2 December 17th, 2008 07:37 PM
How to embed javascript in php code scoobie PHP How-To 8 November 28th, 2007 02:11 PM
embed external device thelip BOOK: Beginning ASP 3.0 0 September 19th, 2006 05:14 AM
Flash embed prob using XHTML socoolbrewster HTML Code Clinic 3 October 20th, 2005 08:44 AM
embed images in html allang Pro JSP 0 August 22nd, 2004 09:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.