Reputation: 709
I have transformed an XHTML file into other XHTML file with XSLT. It has been successfully transformed and the output looks the same as the desired one but the transformed output doesn't display anything when its opened in the browser and in dreamweaver also the color of all the tags remain black from </head>
tag onward instead of usual multi-colors. Find the screen shot of my output attached and also my code. Please help me out to sort out this problem.
Thanking you!
Input File
<?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 name="generator" content=
"HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />
<meta http-equiv="Content-type" content="text/html; charset=us-ascii" />
<script type="t/j" src="abc.js">
</script>
<title></title>
</head>
<body>
<div id="o">
<div id="m">
<div id="nD">
<p id="nT">Part 1</p>
</div>
<div class="TF" id="123">
<script type="t/j" src="xyz.js"></script>
<script type="t/j" src="abc.js"></script>
<div class="iD">
<img alt="" src="ic.gif" /> <span class="iDe">ABC</span><br />
<div class="iDev">
<div id="ta12" class="bl" style="dis:bl"></div>
<div class="q">
<div id="t0b" class="block">
1<span style="color">TEXT1</span>
</div><br />
T <input type="radio" name="o0" id="t0" onclick="getFeedback()" />
F <input type="radio" name="op0" id="f0" onclick="getFeedback()" />
<div id="18">C</div>
<div id="sfb"></div>
</div><br />
</div>
</div>
</div>
</div>
</div>
</body>
</html>
My XSLT:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" version="1.0" exclude-result-prefixes="xhtml">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xhtml:body">
<script type="t/j" src="pqr.js" xml:space="preserve"/>
<script type="t/j" src="stu.js" xml:space="preserve"/>
<body onload="loadPage()" onunload="unloadPage()">
<xsl:apply-templates select="@*|node()"/>
</body>
</xsl:template>
<xsl:template match="xhtml:div[@id='123']/@*">
<xsl:attribute name="class">QT</xsl:attribute>
<xsl:attribute name="id">456</xsl:attribute>
</xsl:template>
<xsl:template match="xhtml:script[@src='xyz.js']">
<xsl:copy>
<xsl:apply-templates select="@*[not(@src)]"/>
<xsl:attribute name="src">lmn.js</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xhtml:body//xhtml:script[@src='abc.js']"/>
<xsl:template match="@onclick"/>
<xsl:template match="xhtml:body//xhtml:div[@id='19']"/>
<xsl:template match="xhtml:div[@class='iD']">
<form name="form">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<xsl:apply-templates select="following-sibling::xhtml:div[1]" mode="inside-form"/>
<br/>
<input type="submit" name="sub" value="Done"/>
</form>
</xsl:template>
<xsl:template match="xhtml:div[@id='ta12']">
<xsl:copy>
<xsl:attribute name="class">pa</xsl:attribute>
<xsl:attribute name="value">10</xsl:attribute>
</xsl:copy>
</xsl:template>
<xsl:template match="xhtml:div[@id='t0b']">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="id">ta0b8</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xhtml:input[@name='o0']">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="name">key0b8</xsl:attribute>
<xsl:attribute name="class">block</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xhtml:input[@name='op0']">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="name">key0b8</xsl:attribute>
<xsl:attribute name="class">block</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Output Screenshot-
Please see in the above image all the tags are in black from closing head tag onward and also the design section is blank.
Upvotes: 2
Views: 473
Reputation: 243529
I get output if I change:
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
to:
<xsl:output method="html" indent="yes" encoding="UTF-8"/>
Upvotes: 2