<xsl:apply-templates> effect on DOM object type?

C

C.W.Holeman II

I am using Firefox 2.0.0.3 on MSWindows.
I have an XML file http://emle.sourceforge.net/emle020000/testb.xml
which invokes an XSLT file http://emle.sourceforge.net/emle020000/testb.xsl

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet href="testb.xsl" type="text/xsl"?>
<z xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<x/>
</z>


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput
method="xml"
encoding="iso-8859-1"
indent="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
/>

<xsl:template match="/z">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
.... DEBUG CODE DELETED. ...
</head>
<body onload="init();">
<div>
<xsl:apply-templates select="x" />
</div>
</body>
</html>
</xsl:template>

<xsl:template match="x">
<span>
<svg xmlns="http://www.w3.org/2000/svg" />
</span>
</xsl:template>

</xsl:stylesheet>


The result of the transform is:
<!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"><head
xmlns="http://www.w3.org/1999/xhtml"><script type="text/javascript">
function init() { lu = function luf(){return
'http://www.w3.org/1999/xhtml';}; var span = document.evaluate("//span",
document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)
..singleNodeValue; var div = document.evaluate("//xhtml:div", document,
lu, XPathResult.FIRST_ORDERED_NODE_TYPE, null) .singleNodeValue;
alert("span:" + span + " div:" + div); return; } </script></head><body
xmlns="http://www.w3.org/1999/xhtml" onload="init();"> <div> <span> <svg
xmlns="http://www.w3.org/2000/svg"/> </span> </div></body></html>The alert
displays span as an Element object and the div as an HTMLDivElement.
What is it about the <xsl:template match="x"> that has this effect?
 
C

C.W.Holeman II

Wrapped lines fixed.

I am using Firefox 2.0.0.3 on MSWindows.
I have an XML file http://emle.sourceforge.net/emle020000/testb.xml
which invokes an XSLT file http://emle.sourceforge.net/emle020000/testb.xsl

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet href="testb.xsl" type="text/xsl"?>
<z xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<x/>
</z>


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput
method="xml"
encoding="iso-8859-1"
indent="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
/>

<xsl:template match="/z">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
.... DEBUG CODE DELETED. ...
</head>
<body onload="init();">
<div>
<xsl:apply-templates select="x" />
</div>
</body>
</html>
</xsl:template>

<xsl:template match="x">
<span>
<svg xmlns="http://www.w3.org/2000/svg" />
</span>
</xsl:template>

</xsl:stylesheet>


The result of the transform is:

<!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">
<head xmlns="http://www.w3.org/1999/xhtml">
<script type="text/javascript">
function init() {
lu = function luf(){return 'http://www.w3.org/1999/xhtml';};
var span = document.evaluate("//span",
document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)
.singleNodeValue;
var div = document.evaluate("//xhtml:div",
document, lu, XPathResult.FIRST_ORDERED_NODE_TYPE, null)
.singleNodeValue;
alert("span:" + span + " div:" + div);
return;
}
</script>
</head>
<body xmlns="http://www.w3.org/1999/xhtml" onload="init();">
<div>
<span>
<svg xmlns="http://www.w3.org/2000/svg"/>
</span>
</div>
</body>
</html>

The alert displays span as an Element object and the div as an
HTMLDivElement.
What is it about the <xsl:template match="x"> that has this effect?
 
C

C.W.Holeman II

Joseph Kesselman said:
XSLT is namespace-aware. Your stylesheet copies a <span> element with no
namespace into the output document, which means it won't be recognized as
being an XHTML span element.

Change your code to:

<xsl:template match="x">
<span xmlns="http://www.w3.org/1999/xhtml">
<svg xmlns="http://www.w3.org/2000/svg" />
</span>
</xsl:template>

Martin Honnen said:
Add
xmlns="http://www.w3.org/1999/xhtml"
to the xsl:stylesheet element, that way all your literal XHTML elements
will be in the XHTML namespace. Otherwise in any template you write you
will need to make sure that the XHTML default namespace declaration is set
for XHTML elements.

That does it. Thanks again. Corrected and working version:

http://emle.sourceforge.net/emle020000/testb2.xml
http://emle.sourceforge.net/emle020000/testb2.xsl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,008
Messages
2,570,268
Members
46,867
Latest member
Lonny Petersen

Latest Threads

Top