HI,
I am very new to XSLT..
I am trying to have identity-copy of my html, and change a few things, but the result gives me extra <html><body></body></html>
after my </html>

here's my xsl:

<xsl:stylesheet version='1.0' 
        xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

 <xsl:template match='node()|@*' >
	<xsl:copy>
		<xsl:apply-templates select='node()|@*' />
	</xsl:copy>
</xsl:template>

<xsl:template match='h2'>
     <xsl:copy>
	 <font color='red'><xsl:value-of select='.'/></font>
     </xsl:copy>
</xsl:template>

<xsl:template match="div[@class]">
	<xsl:copy>
		<xsl:copy-of select='@*'/>
		<xsl:apply-templates select="div/@id">
			<xsl:sort/>
		</xsl:apply-templates>
	</xsl:copy>
</xsl:template>

<xsl:template match="div/@id">
	<xsl:copy-of select='..'/>
</xsl:template>	

</xsl:stylesheet>

how can I not have the extra nodes?
appreciate any helps..

TQ in advance! :-)

Recommended Answers

All 4 Replies

Put ur XML data here which u r using as a input.

Put ur XML data here which u r using as a input.

Hi Varun,
here's my data in php file - i'm new to PHP too :(

<?php
 session_start();
 echo 'test ' . $_SESSION['mytest'];
 echo <<<tst
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
 <head>
   <meta http-equiv="content-type" content="text/html;        charset=utf-8" />
		<title>test3...</title>
		<link rel="stylesheet" type="text/css" href="test.css" /> 
		<!-- <link rel="stylesheet" type="text/css" href="css/frmt.css"/> -->
		<!--script language="Javascript" type="text/javascript" src="a.js" /-->
	</head>
	<body>		
		<div class="cnt">
			<div class="s1" id='m3'>m1</div>
			<div class="s2" id='m2'>m2</div>
			<div class="s3" id='m1'>m3</div>
		       <div class="s4" id="m4"><h2>test..</h2></div>
			<div class="s5" id="m5"><h2>another test</h2>
				<img src="test.jpg" alt="test" />
			</div>			
		</div>
	</body>
</html>
tst;
?>

and I use this to transform:

$pg = new DOMDocument();
	$pg->loadHTMLFile('test3.php');
		
	$xsl = new DOMDocument();
	$xsl->load('test3.xsl');
	$proc = new XSLTProcessor();
	$proc->importStylesheet($xsl);

	echo $proc->transformToXml($pg);

thanks again!
:)

hi,

xslt is not giving any extra tag. may be ur php code is doing something wrong. i dont know about php bur there is no problem in ur xslt which u have given.

TQ.. yup, you're right.. it's my php code that gave the prob..

(sorry for the late reply.. been away..)

Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.