RE: [xsl] is it possible to construct new xml with xsl ?

Subject: RE: [xsl] is it possible to construct new xml with xsl ?
From: "Michael Leditschke" <mike@xxxxxxxxxxx>
Date: Mon, 17 Jun 2002 12:05:13 +1000
<snip/>

> IE will assume the output of the transformation is meant to be 
> interpreted as 
> HTML. If you want collapsible views, you need to use a stylesheet 
> that will 
> produce the (D)HTML that makes the browser produce the view you want. See
>   http://www.dpawson.co.uk/xsl/sect2/microsoft.html#d58e229


I had a look at this stylesheet and have a concern about the
way in which the XML declaration is being generated.



To my knowledge, the XML Declaration is not a PI per the XML 1.0
spec (section 2.6). Correct? 

Is it illegal for a parser to pass it through as a PI? I would 
have thought it was illegal given the BNF in the XML 1.0 spec.


Conclusion -> No parser should pass the XML declaration to
              an application. 



The XPath 1.0 data model is explicit in section 5.5 that 

"The XML declaration is not a processing instruction. 
Therefore, there is no processing instruction node 
corresponding to the XML declaration."

The XSL spec adopts the XPath data model without mention
of adding the XML declaration as a PI.

Conclusion -> Even if a parser were allowed to pass the
              XML declaration through as a PI, it is not 
              represented as such in the XSLT data model.



Now, when displaying a file in IE using the referenced template,
it does show the xml declaration as provided in the file. If
no declaration in the file, there's none in the display, etc.

The stylesheet has a template that starts 

<xsl:template match="pi('xml')">

Given the above references, and the operation of IE, 
am I correct in assuming


1. MSXML is (incorrectly) passing through the XML declaration 
as a PI in order to render it per the stylesheet.


OR


2. It's not just the stylesheet contributing to the displayed 
information. Some additional code must be being invoked to 
detect this stylesheet, and somehow get at and render the XML 
declaration information, which to my knowledge is supposed 
to be hidden from the application by the parser.


I tried writing a stylesheet of my own looking 
for an 'xml' PI and tested it with IE, the results of which 
suggested MSXML is not passing through the declaration as a PI, 
so 2) above looks more likely. 

Source document

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="hello.xsl"?>
<greeting>Hello, world!</greeting>


Stylesheet

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:template match="/">
    <html>
      <head>
        <title>XML Declaration test</title>
      </head>
      <body>
        <p>
          <xsl:choose>
            <xsl:when test="processing-instruction('xml')">
XML Declaration passed through as PI.</xsl:when>
            <xsl:otherwise>
XML Declaration not passed through as PI.</xsl:otherwise>
          </xsl:choose>
        </p>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>


Result

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">
<title>XML Declaration test</title>
</head>
<body>
<p>XML Declaration not passed through as PI.</p>
</body>
</html>


If the stylesheet authors/modifiers are out there (Nate Austin or 
Jonathan Marsh), would you care to comment?


Regards
Michael



BTW I tried the MS stylesheet out with SAXON 5.6.2, and as expected,
the xml declaration information was missing in the resulting 
HTML. 



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread