xproc / 3.0-steps

Repository for change requests to the standard step library and for official extension steps
10 stars 7 forks source link

Content-types of ports "source" and "result" on p:insert: Allow text documents? #583

Closed xml-project closed 2 months ago

xml-project commented 4 months ago

I think there is an edge case, where the result of p:insert can be a text document. If the document on port "source" is an XML document which contains just a document node (no element nodes), and then I insert a text document, I think I should get a text document. But the current specification says, port "result" on p:insert is either XML or HTML.

Proposal: Add "text" to the possible content types of port "result".

Does this make sense?

ndw commented 4 months ago

Isn't an XML document that contains just a text node a, uh, text document? How did that get into the step without tripping over the constraint on source?

Do we want to allow text on the source as well as the result?

(I'm in favor, I'm just trying to see if we've covered all the bases.)

xml-project commented 4 months ago

Sorry for being not precise: I am talking about XProc 3.1, where a text document is allowed on port "insertion". Now I do:

<p:delete match="/doc">
   <p:with-input><doc /></p:with-input>
</p:delete>
<!-- result: An XML document with just a document node -->
<p:insert match="/" position="last-child">
   <p:with-input><p:inline content-type="text/plain">This is a text</p:inline></p:with-input>
</p:insert>

The result is a document node with one text node. So it should be, as you said, a text document. But the signature of p:insert is:

<p:output port="result" content-types="xml html"/>
ndw commented 4 months ago

I agree that we should add text to the content types of result.

Tangentially, I'm wondering what the result of your p:delete step is, though. According to p:delete:

If the resulting document contains exactly one text node, the content-type property is changed to text/plain and the serialization property is removed, while all other document properties are preserved. In all other cases, all document properties are preserved.

The only way that can happen is if you delete the root node, as you're doing in the example above. I suppose, technically, the result of that deletion is a completely empty document, not a document containing exactly one text node. But I think I assume that it becomes a text document. And then it wouldn't be allowed on the source port of p:insert. Which it probably should be.