Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > b3bdfe6d859a3d6920ff2c44b38e9a6f > files > 338

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="extensions" page="functions" subpage="serialize"/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: saxon:serialize()</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title" content="Saxonica: XSLT and XQuery Processing: saxon:serialize()"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>saxon:serialize()</h1>
      <p><b>saxon:serialize($node as node(), $format as xs:string)</b></p>
      <p><b>saxon:serialize($node as node(), $format as element(xsl:output))</b></p>
      <p>This function takes two arguments: the first is a node (generally a document or element node)
to be serialized. The second argument defines the serialization properties. The second argument takes
several possible forms:</p>
      <ul>
         <li content="para">
            <p>When called within an XSLT stylesheet, the second argument may be the name of an 
<code>xsl:output</code> element in the stylesheet, written as a string literal (it must be a literal,
or at any rate, an expression that is evaluated at compile time).</p>
         </li>
         <li content="para">
            <p>In non-XSLT environments, the second argument
may be the name of the output method (xml, html, xhtml, text), written as a string literal.
In this case the other serialization parameters are defaulted.</p>
         </li>
         <li content="para">
            <p>In all environments, the second argument may be an <code>xsl:output</code> element
conforming to the rules defined in the XSLT specification. This element may be constructed
dynamically, and may therefore be used to decide all the serialization properties dynamically.</p>
         </li>
      </ul>
      <p>For example, the function may be used as follows in XQuery:</p>
      <div class="codeblock"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">
         <pre>
            <code>
declare namespace saxon="http://saxon.sf.net/";
declare namespace xsl="http://www.w3.org/1999/XSL/Transform";

&lt;out&gt;{
let $x := &lt;a&gt;&lt;b/&gt;&lt;c&gt;content&lt;/c&gt;&lt;?pi?&gt;&lt;!--comment--&gt;&lt;/a&gt;
return saxon:serialize($x, &lt;xsl:output method="xml" 
                             omit-xml-declaration="yes" 
                             indent="yes" 
                             saxon:indent-spaces="1"/&gt;)
}&lt;/out&gt;
</code>
         </pre>
      </div>
      <p>The function serializes the specified document, or the subtree rooted at the specified element, according
to the parameters specified, and returns the serialized document as a string.</p>
      <p>This function is useful where the stylesheet or query wants to manipulate the serialized output,
for example by embedding it as CDATA inside another XML document, or prefixing it with a DOCTYPE
declaration, or inserting it into a non-XML output file.</p>
      <p>Note that because the output is a string, the encoding parameter has no effect on the actual encoding,
though it does affect what is written to the XML declaration.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="sort.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>