output-method
Syntax
output-method output-format {
cdata-section-elements name-list;
doctype-public string;
doctype-system string;
encoding string;
indent "yes" | "no";
media-type string;
omit-xml-declaration "yes" | "no";
standalone "yes" | "no";
version string;
}Description
Define the style used for result tree output. You must define the output-method
statement as a top-level statement in the script. Output formats include HTML, JSON,
text, or XML. The default is XML, unless the first child element of the root node is
<html> and there are no preceding text nodes, in which
case the default output format is HTML.
Attributes
output-format |
The format of the output. The default is XML, unless the first child
element of the root node is JSON format is supported starting in SLAX version 1.3. The script generates JSON-compatible XML and the results are then translated to JSON.
|
cdata-section-elements name-list |
Specify a space-delimited list of the names of output elements whose text contents should be output to the result tree using CDATA sections. A CDATA section starts with "<![CDATA[" and ends with "]]>", and the contents of the section are interpreted by an XML parser as character data only, rather than markup. |
doctype-public string |
Add the DOCTYPE declaration
to the result tree, and specify the value of the |
doctype-system string |
Add the DOCTYPE declaration
to the result tree, and specify the value of the |
encoding string |
Explicitly add the pseudo-attribute |
indent "yes" | "no" |
Specify whether to indent the result tree output according to the hierarchical structure. Acceptable values are “yes” and “no”.
|
media-type string |
Define the MIME content type of the output.
|
omit-xml-declaration "yes" | "no" |
Specify whether to include or omit the
XML declaration (
|
standalone "yes" | "no" |
Explicitly add the pseudo-attribute |
version string |
For HTML and XML formats,
set the W3C version for the output format. The pseudo-attribute |
SLAX Example
The following example uses the output method XML, which
creates an XML declaration in the result tree output and adds the
pseudo-attributes version, encoding, and standalone to the declaration. The DOCTYPE declaration has the root element <html> and provides values for both the PUBLIC and the SYSTEM attributes.
version 1.1;
output-method xml {
doctype-public "-//W3C//DTD XHTML 1.0 Transitional//EN";
doctype-system "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
encoding "utf-8";
indent "yes";
omit-xml-declaration "no";
standalone "no";
version "1.0";
}
match / {
<html> {
<script type="text/javascript" src="/assets/js/api.js">;
/* ... */
}
}The script produces the following output:
<?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <script type="text/javascript" src="/assets/js/api.js"></script> ... </html>
The following example is similar to the previous example
except that the script does not specify an output format. Since the
first child element of the root node is <html>, the output format defaults to HTML.
version 1.1;
output-method {
doctype-public "-//W3C//DTD XHTML 1.0 Transitional//EN";
doctype-system "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
encoding "utf-8";
indent "yes";
omit-xml-declaration "no";
standalone "no";
version "1.0";
}
match / {
<html> {
<script type="text/javascript" src="/assets/js/api.js">;
/* ... */
}
}The default output format is HTML. The XML declaration is omitted from the output.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html><script type="text/javascript" src="/assets/js/api.js"></script></html>
Release Information
Statement introduced in SLAX version 1.1.
Support for JSON format added in SLAX version 1.3.