RE: serializing a forrest into the output (not to a file)

Thanks for the comment. As you probably know, Saxon includes an extension
function saxon:serialize which does essentially what you are describing. I
have a similar requirement when including the "schema for XSLT" in the HTML
rendition of the XSLT 2.0 working draft. 

But my instinct is not to include this feature in the spec this time round.
It's probably something that should go into EXSLT first, to see whether
vendors and users find it attractive, before putting it in the core
specification.

Michael Kay
Software AG

> -----Original Message-----
> From: Tobias Reif [mailto:tobiasreif@pinkjuice.com] 
> Sent: 29 April 2003 10:55
> To: public-qt-comments@w3.org
> Subject: serializing a forrest into the output (not to a file)
> 
> 
> 
> Hi
> 
> I need to serialize forrests into the output (not to a file). 
> There are more than four different ways to do this, but all I 
> know are are clumsy and verbose.
> 
> I suggest to add something like xsl:serialize to XSLT 2.
> 
> Use cases: All cases where some tree or forrest is to be 
> included in the result tree or forrest, in serialized form.
> 
> This can be desired when the result of a transformation is to 
> be included in a program listing.
> 
> Real world example:
>    http://www.pinkjuice.com/doxy/doc/
> The content will move, so here's a pair of relevant snippets: 
> (snightly formatted and shortened)
> 
> # What it looks like in the browser: #################################
> 
> Literal
> Test 9 failed
> 
> Input
> 
> <simpara>
> <literal>foo</literal>
> </simpara>
> 
> Desired Output
> 
> <p class="simpara">
> <span class="literal">foo</span>
> </p>
> 
> Output
> 
> <p class="simpara">
> <!-- literal not yet fully supported -->
> foo
> </p>
> 
> 
> # The XHTML source ###################################################
> 
> <div class="section">
> 
> <h3 class="title">Literal</h3>
> <h4 class="title">Test 9 <em>failed</em></h4>
> 
> <h3 class="title">Input</h3>
> <div class="para">
> <pre><code>&lt;simpara&gt;
> &lt;literal&gt;foo&lt;/literal&gt;
> &lt;/simpara&gt;</code></pre>
> </div>
> 
> <h3 class="title">Desired Output</h3>
> <div class="para">
> <pre><code>&lt;p class="simpara"&gt;
> &lt;span class="literal"&gt;foo&lt;/span&gt;
> &lt;/p&gt;</code></pre>
> </div>
> 
> <h3 class="title">Output</h3><div class="para"> 
> <pre><code>&lt;p class="simpara"&gt;
> &lt;!-- literal not yet fully supported --&gt;
> foo
> &lt;/p&gt;</code></pre>
> </div>
> 
> </div>
> 
> ######################################################################
> 
> Example showing the suggested feature:
> 
> $snippet is a forrest, for example the result of a transformation:
> 
> <xsl:variable name="snippet">
>    <xsl:apply-templates select="$input_snippet" mode="foo"/> 
> </xsl:variable>
> 
> Serialized it looks like this:
> 
> <p>f</p>
> <p>f</p>
> 
> Pseudo code showing what I suggest:
> 
> ######################################################################
> 
> <xsl:output
>    name="xml_snippet"
>    method="xml"
>    indent="no"
>    omit-xml-declaration="yes"
>    />
> 
> <programlisting>
>    <xsl:serialize format="xml_snippet">
>      <xsl:copy-of select="$snippet"/>
>    </xsl:serialize>
> </programlisting>
> 
> # Output: ############################################################
> 
> <programlisting>&lt;p&gt;f&lt;/p&gt;
> &lt;p&gt;f&lt;/p&gt;</programlisting>
> 
> ######################################################################
> 
> Definition of xsl:serialize:
> 
> <!-- Category: instruction -->
> <xsl:serialize
>    format = qname
>    type-information = "strict" | "lax" | "preserve" | "none">
>    <!-- Content: content-constructor -->
> </xsl:serialize>
> 
> xsl:serialize has the same attributes as xsl:result-document, 
> except href.
> 
> It serializes its content just as xsl:result-document does;
> But the result is output in place, instead of being written to a file.
> 
> [an example like the above]
> 
> ######################################################################
> 
> Alternatively, instead of adding xsl:serialize, the 
> definition of xsl:result-document could be changed, to 
> include something like
> 
> "If the href attribute is present, the result of evaluating 
> the xsl:result-document instruction is an empty sequence. 
> This means it does not contribute any nodes to the result of 
> the content constructor it is part of.
> 
> If the href attribute is not present, the result of the 
> serialization is output in place, and not written to a file. 
> This means it contributes one text node [correct?] to the 
> result of the content constructor it is part of."
> 
> Tobi
> 
> -- 
> http://www.pinkjuice.com/
> 

Received on Tuesday, 29 April 2003 06:43:30 UTC