[xsl] XML string copying w/o d-o-e (was Re: Fixing <b>)

Subject: [xsl] XML string copying w/o d-o-e (was Re: Fixing <b>)
From: Mike Brown <mike@xxxxxxxx>
Date: Sun, 31 Mar 2002 21:30:03 -0700 (MST)
Michael Kay wrote:
> I think one could clean up the semantics to make it workable. I'm
> thinking in terms of a facility that says "Here is some XML, represented as
> unparsed text containing markup characters. I want this XML copied onto the
> result tree. Conceptually, I want to parse the XML and copy the resulting
> nodes to the result tree. But if the result tree is being serialized to XML,
> I don't mind the processor being clever and bypassing the parse/serialize
> operations by copying the raw XML straight to the serial output file."

I don't see how you could ever get away with bypassing the parse operation.  
How else will you get it into the result tree in the right structure, as
opposed to as a text node? Besides, if you don't parse it, you can't be sure
that it's going to be OK to copy its "preserialized" form to the output, so it
can't be any better than just using disable-output-escaping on a text node.

And I shudder at the thought of helping people wrap their heads around the "<"
and "&" and newline-in-attribute-value escaping issues, character and entity
references, and their interaction with the result tree. Not that those things 
are easy as it is.

Also, given:

  <foo someXML="&lt;elem attr1=&quot;&amp;quot;hello world&amp;quot;&quot;/>"/>

and:

  <xsl:template match="foo">
    <xsl:copy-of select="@someXML" parse-string-value-as-xml="yes"/>
  </xsl:template>

...you'd produce this structure in the result tree:

  |__element 'elem'
        \__attribute 'attr1' with value '"hello world"'

And I guess this element would be flagged in the processor with a
preserialized string (the original someXML attribute value) to use when
serializing the result tree.

So far, so good, but what if the next XSLT instruction were

  <xsl:attribute name="attr2">:-)&#xA;:-(</xsl:attribute>

?

You'd have to explain in the spec how to go about modifying the preserialized
string to incorporate the new attribute. Yuck. And XSLT forbids adding an
attribute to an element after children have been added to it, so there would
have to be an exception in this case, perhaps (my example here doesn't give
'elem' any children, but you probably see the trouble).

> That doesn't deal with the HTML variant of the problem, though ....

Agreed.

I really don't think the costs of spec'ing out and implementing this kind of 
functionality are outweighed by the benefits.

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

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


Current Thread