Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > b3bdfe6d859a3d6920ff2c44b38e9a6f > files > 3009

saxon-manual-9.4.0.9-2.mga7.noarch.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="sourcedocs" page="streaming" subpage="furtherprocessing"/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: Processing the nodes returned by saxon:stream()</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: Processing the nodes returned by saxon:stream()"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Processing the nodes returned by saxon:stream()</h1>
      <p>The nodes selected by the streamed expression may be further processed. For example:</p>
      <p><b>XSLT example</b></p>
      <div class="codeblock"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">
         <pre>
            <code>

&lt;xsl:template name="main"&gt;
  &lt;xsl:apply-templates select="saxon:stream(doc('customers.xml')/*/customer)"
                       xmlns:saxon="http://saxon.sf.net/"/&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="customer"&gt;
  &lt;xsl:value-of select="code, name, location" separator="|"/&gt;
  &lt;xsl:text&gt;&amp;#xa;&lt;/xsl:text&gt;
&lt;/xsl:template&gt;
</code>
         </pre>
      </div>
      <p><b>XQuery example</b></p>
      <div class="codeblock"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">
         <pre>
            <code>
declare function f:customers() {
   saxon:stream(doc('customers.xml')/*/customer)
};

for $c in f:customers() 
return concat(string-join(($c/code, $c/name, $c/location), '|'), '&amp;#xa;')

</code>
         </pre>
      </div>
      <p>Conceptually, <code>saxon:stream()</code> evaluates the sequence supplied in its
first argument as a sequence of nodes, and then makes copies of these nodes as described
in the rules of the <code>xsl:copy-of</code> instruction. The significance of the (notional) copy operation
is that the returned nodes have no ancestors or siblings; each is the root of its own tree.</p>
      <p>The document that is processed in streaming mode must be read
using the <code>doc()</code> function (or in XSLT, the <code>document()</code>
function). The query or stylesheet may also process other documents (for example
a document named on the command line) but this is not necessary. In XSLT it is often
useful to activate the stylesheet at a named template using the <code>-it</code>
option on the command line, which allows activation without a primary
input document.</p>
      <p>When streaming copy is used, the relevant calls on the <code>doc()</code> or <code>document()</code>
functions are not <i>stable</i>: that is, there is no guarantee that if the same document is read more
than once, its contents will be unchanged. This is because the whole point of the facility is to ensure
that Saxon does not need to keep the content of the document in memory. This limitation explains the
choice of the keyword <code>read-once</code>: the facility should not be used to process a document if
it needs to be read more than once during the query or transformation.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="partialreading.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>