Project

Profile

Help

Support #4396

closed

Empty element tags not compatible with result-document ixsl methods

Added by David Priest over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
-
Sprint/Milestone:
-
Start date:
2019-11-26
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

Using ixsl:replace-content or ixsl:append-content does not work with short-form empty element tags, i.e. <div id="shortformEmptyDiv"/>. I would be surprised if this is not already known, but here is an example:

index.html

<!DOCTYPE html>
<html
	xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Bug Demo</title>
		<script src="js/Saxon-JS-1.2.0/SaxonJS.min.js"></script>
		<script type="text/javascript">
			window.onload = function() { 
				SaxonJS.transform({ 
					stylesheetLocation: "bug.sef.xml", 
					initialTemplate: "Q{http://www.w3.org/1999/XSL/Transform}initial-template", 
					}); 
				}
		</script>
	</head>
	<body>
		<div id="longformEmptyDiv"></div>
		<div>Here is some placeholder content.</div>
		<div id="shortformEmptyDiv"/>
		<div>Here is some placeholder content.</div>
		<div id="disappearingAct"></div>
		<div>Here is some placeholder content.</div>
	</body>
</html>

bug.xsl

<xsl:transform
	expand-text="yes"
	extension-element-prefixes="ixsl"
	version="3.0"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
	xmlns:js="http://saxonica.com/ns/globalJS"
	xmlns:xhtml="http://www.w3.org/1999/xhtml"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template
		name="xsl:initial-template">
		<xsl:apply-templates select="ixsl:page()" />
	</xsl:template>

	<xsl:template
		match="div[@id='shortformEmptyDiv']">
		<xsl:message>Matched shortformEmptyDiv</xsl:message>
		<xsl:result-document href="?." method="ixsl:replace-content">
			<p>Here is some shortformEmptyDiv content.</p>
		</xsl:result-document>
	</xsl:template>

	<xsl:template
		match="div[@id='longformEmptyDiv']">
		<xsl:message>Matched longformEmptyDiv</xsl:message>
		<xsl:result-document href="?." method="ixsl:replace-content">
			<p>Here is some longformEmptyDiv content.</p>
		</xsl:result-document>
	</xsl:template>

	<xsl:template
		match="div[@id='disappearingAct']">
		<xsl:message>Matched disappearingAct</xsl:message>
		<xsl:result-document href="?." method="ixsl:replace-content">
			<p>Here is some disappearingAct content.</p>
		</xsl:result-document>
	</xsl:template>
</xsl:transform>

browser result:

<html
	xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Bug Demo</title>
		<script src="js/Saxon-JS-1.2.0/SaxonJS.min.js"></script>
		<script type="text/javascript">
			window.onload = function() { 
				SaxonJS.transform({ 
					stylesheetLocation: "xsl/bug.sef.xml", 
					initialTemplate: "Q{http://www.w3.org/1999/XSL/Transform}initial-template", 
					}); 
				}
		</script>
	</head>
	<body>
		<div id="longformEmptyDiv">
			<p>Here is some longformEmptyDiv content.</p>
		</div>
		<div>Here is some placeholder content.</div>
		<div id="shortformEmptyDiv">
			<p>Here is some shortformEmptyDiv content.</p>
		</div>
	</body>
</html>

You will note that the match on longformEmptyDiv correctly inserted the replacement content as a child of the div itself. However, on shortformEmptyDiv the content has replaced everything following the short form div, instead of being inserted into the div. (Consequently, the disappearingAct div goes AWOL. Indeed, its match is never made: no message appears in the browser console: the short form replacement was performed before the disappearingAct template could match.)

SaxonJS 9.8, 9.9


Files

index.html (688 Bytes) index.html David Priest, 2019-11-26 19:52
bug.xsl (1.27 KB) bug.xsl David Priest, 2019-11-26 19:52

Please register to edit this issue

Also available in: Atom PDF