Support #4321


PI output bug in @method="html"

Added by Toshihiko Makita almost 3 years ago. Updated almost 3 years ago.

Start date:
Due date:
% Done:


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



I'm working with DITA to HTML5 project and generating HTML with PHP instructions. As you know PHP instruction is written in processing-instruction like this:

<?php includeInnerHtml('C_19.php')?>

However when I generate processing-instruction in HTML output, Saxon does not close the processing-instruction by "?>".

Here is sample XSLT file and the result:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=""
    exclude-result-prefixes="xs math"
    <xsl:output method="html" encoding="UTF-8" html-version="5.0"/>
    <xsl:template name="xsl:initial-template">
        <!-- XSLT processor information -->
        <xsl:variable name="vendor" as="xs:string" select="system-property('xsl:vendor')"/>
        <xsl:variable name="vendorUrl" as="xs:string" select="system-property('xsl:vendor-url')"/>
        <xsl:variable name="productName" as="xs:string" select="system-property('xsl:product-name')"/>
        <xsl:variable name="productVersion" as="xs:string" select="system-property('xsl:product-version')"/>
                <title>Saxon PI Output Test</title>
                    <xsl:comment select="'Running on: ' || $productName || ' (' || $vendorUrl || ') Version: ' || $productVersion"/>
                    <p>Here is PI output:</p>
                    <xsl:processing-instruction name="php">includeInnerHtml('C_19.php')</xsl:processing-instruction>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Saxon PI Output Test</title>
      <main><!--Running on: SAXON ( Version: PE>
         <p>Here is PI output:</p>
         <?php includeInnerHtml('C_19.php')></main>

This occurs only HTML output. If I change @method="xml", this phenomenon does not occur.

Please fix this problem.


Toshihiko Makita

Actions #1

Updated by Michael Kay almost 3 years ago

This behaviour is in accordance with section 7.3 of the XSLT 3.0/XQuery 3.1 Serialization specification at :

The HTML output method MUST terminate processing instructions with > rather than ?>. It is a serialization error [err:SERE0015] to use the HTML output method when > appears within a processing instruction in the data model instance being serialized.

This reflects the rule in HTML 4.01

A processing instruction begins with <? and ends with >

I have not been able to find any reference to processing instruction syntax in the HTML5 specifications, though they do refer to processing instruction nodes in the data model.

I would be interested to know if there are any practical use cases for processing instructions in HTML, and whether either syntax is accepted or rejected by deployed HTML browsers.

Actions #2

Updated by Toshihiko Makita almost 3 years ago

Dr. Kay,

Thank you for your reply.

I understand that processing-instruction definition differs between HTML and XML.

For your reference <?php [PHP instruction] ?> is interpreted by server PHP processor and never passed to browser applications in client side.

Also processing-instruction seems to be inhibited in HTML5 specification: Tag open state

Please close this ticket.


Toshihiko Makita

Actions #3

Updated by Michael Kay almost 3 years ago

As a workaround for generating PHP code, I would suggest one of the following:

(a) Use method="xhtml"

(b) Use character-maps to output the "" and "?>" delimiters, perhaps from some obscure characters like ⬅︎ and ➡︎.

(c) Add a "?" within the content of the PI, so it's serialized as "?>".

(d) Write some Java to customize the serializer - not as difficult as it might seem (call Configuration.setSerailizerFactory, supplying a subclass of SerializerFactory that overrides newHTMLEmitter() to return a subclass of HTML50Emitter which overrides the processingInstruction() method)

Actions #4

Updated by Michael Kay almost 3 years ago

  • Tracker changed from Bug to Support
  • Status changed from New to Closed
  • Assignee set to Michael Kay

Closed: the product is working correctly and as required by the W3C specifications.

Please register to edit this issue

Also available in: Atom PDF