XML-XSLT

 view release on metacpan or  search on metacpan

examples/REC-xslt-19991116.xml  view on Meta::CPAN

<p>The argument must evaluate to a string that is a <xnt
href="&XMLNames;#NT-QName">QName</xnt>.  The <xnt
href="&XMLNames;#NT-QName">QName</xnt> is expanded into an <xtermref
href="&XPath;#dt-expanded-name">expanded-name</xtermref> using the
namespace declarations in scope for the expression. The
<function>element-available</function> function returns true if and
only if the expanded-name is the name of an instruction.  If the
expanded-name has a namespace URI equal to the XSLT namespace URI,
then it refers to an element defined by XSLT.  Otherwise, it refers to
an extension element. If the expanded-name has a null namespace URI,
the <function>element-available</function> function will return
false.</p>

<proto name="function-available" return-type="boolean"><arg
type="string"/></proto>

<p>The argument must evaluate to a string that is a <xnt
href="&XMLNames;#NT-QName">QName</xnt>.  The <xnt
href="&XMLNames;#NT-QName">QName</xnt> is expanded into an <xtermref
href="&XPath;#dt-expanded-name">expanded-name</xtermref> using the
namespace declarations in scope for the expression. The
<function>function-available</function> function returns true if and
only if the expanded-name is the name of a function in the function
library. If the expanded-name has a non-null namespace URI, then it
refers to an extension function; otherwise, it refers to a function
defined by XPath or XSLT.</p>

</div1>

<div1 id="output">
<head>Output</head>

<e:element-syntax name="output">
  <e:in-category name="top-level-element"/>
  <e:attribute name="method">
    <e:constant value="xml"/>
    <e:constant value="html"/>
    <e:constant value="text"/>
    <e:data-type name="qname-but-not-ncname"/>
  </e:attribute>
  <e:attribute name="version">
    <e:data-type name="nmtoken"/>
  </e:attribute>
  <e:attribute name="encoding">
    <e:data-type name="string"/>
  </e:attribute>
  <e:attribute name="omit-xml-declaration">
    <e:constant value="yes"/>
    <e:constant value="no"/>
  </e:attribute>
  <e:attribute name="standalone">
    <e:constant value="yes"/>
    <e:constant value="no"/>
  </e:attribute>
  <e:attribute name="doctype-public">
    <e:data-type name="string"/>
  </e:attribute>
  <e:attribute name="doctype-system">
    <e:data-type name="string"/>
  </e:attribute>
  <e:attribute name="cdata-section-elements">
    <e:data-type name="qnames"/>
  </e:attribute>
  <e:attribute name="indent">
    <e:constant value="yes"/>
    <e:constant value="no"/>
  </e:attribute>
  <e:attribute name="media-type">
    <e:data-type name="string"/>
  </e:attribute>
  <e:empty/>
</e:element-syntax>

<p>An XSLT processor may output the result tree as a sequence of
bytes, although it is not required to be able to do so (see <specref
ref="conformance"/>). The <code>xsl:output</code> element allows
stylesheet authors to specify how they wish the result tree to be
output. If an XSLT processor outputs the result tree, it should do so
as specified by the <code>xsl:output</code> element; however, it is
not required to do so.</p>

<p>The <code>xsl:output</code> element is only allowed as a <termref
def="dt-top-level">top-level</termref> element.</p>

<p>The <code>method</code> attribute on <code>xsl:output</code>
identifies the overall method that should be used for outputting the
result tree.  The value must be a <xnt
href="&XMLNames;#NT-QName">QName</xnt>.  If the <xnt
href="&XMLNames;#NT-QName">QName</xnt> does not have a prefix, then it
identifies a method specified in this document and must be one of
<code>xml</code>, <code>html</code> or <code>text</code>.  If the <xnt
href="&XMLNames;#NT-QName">QName</xnt> has a prefix, then the <xnt
href="&XMLNames;#NT-QName">QName</xnt> is expanded into an <xtermref
href="&XPath;#dt-expanded-name">expanded-name</xtermref> as described
in <specref ref="qname"/>; the expanded-name identifies the output
method; the behavior in this case is not specified by this
document.</p>

<p>The default for the <code>method</code> attribute is chosen as
follows.  If</p>

<ulist>

<item><p>the root node of the result tree has an element
child,</p></item>

<item><p>the expanded-name of the first element child of the root node
(i.e. the document element) of the result tree has local part
<code>html</code> (in any combination of upper and lower case) and a
null namespace URI, and</p></item>

<item><p>any text nodes preceding the first element child of the root
node of the result tree contain only whitespace characters,</p></item>

</ulist>

<p>then the default output method is <code>html</code>; otherwise, the
default output method is <code>xml</code>.  The default output method
should be used if there are no <code>xsl:output</code> elements or if
none of the <code>xsl:output</code> elements specifies a value for the
<code>method</code> attribute.</p>

<p>The other attributes on <code>xsl:output</code> provide parameters
for the output method.  The following attributes are allowed:</p>

<ulist>

<item><p><code>version</code> specifies the version of the output
method</p></item>

<item><p><code>indent</code> specifies whether the XSLT processor may
add additional whitespace when outputting the result tree; the value
must be <code>yes</code> or <code>no</code></p></item>

<item><p><code>encoding</code> specifies the preferred character
encoding that the XSLT processor should use to encode sequences of
characters as sequences of bytes; the value of the attribute should be
treated case-insensitively; the value must contain only characters in
the range #x21 to #x7E (i.e. printable ASCII characters); the value
should either be a <code>charset</code> registered with the Internet
Assigned Numbers Authority <bibref ref="IANA"/>, <bibref
ref="RFC2278"/> or start with <code>X-</code></p></item>

<item><p><code>media-type</code> specifies the media type (MIME
content type) of the data that results from outputting the result
tree; the <code>charset</code> parameter should not be specified
explicitly; instead, when the top-level media type is
<code>text</code>, a <code>charset</code> parameter should be added
according to the character encoding actually used by the output
method</p></item>

<item><p><code>doctype-system</code> specifies the system identifier
to be used in the document type declaration</p></item>

<item><p><code>doctype-public</code> specifies the public identifier
to be used in the document type declaration</p></item>

<item><p><code>omit-xml-declaration</code> specifies whether the XSLT
processor should output an XML declaration; the value must be
<code>yes</code> or <code>no</code></p></item>

<item><p><code>standalone</code> specifies whether the XSLT processor
should output a standalone document declaration; the value must be
<code>yes</code> or <code>no</code></p></item>

<item><p><code>cdata-section-elements</code> specifies a list of the
names of elements whose text node children should be output using
CDATA sections</p></item>

</ulist>

<p>The detailed semantics of each attribute will be described
separately for each output method for which it is applicable.  If the
semantics of an attribute are not described for an output method, then
it is not applicable to that output method.</p>

<p>A stylesheet may contain multiple <code>xsl:output</code> elements
and may include or import stylesheets that also contain
<code>xsl:output</code> elements.  All the <code>xsl:output</code>
elements occurring in a stylesheet are merged into a single effective
<code>xsl:output</code> element. For the
<code>cdata-section-elements</code> attribute, the effective value is
the union of the specified values.  For other attributes, the
effective value is the specified value with the highest <termref
def="dt-import-precedence">import precedence</termref>. It is an error
if there is more than one such value for an attribute.  An XSLT
processor may signal the error; if it does not signal the error, if
should recover by using the value that occurs last in the stylesheet.
The values of attributes are defaulted after the
<code>xsl:output</code> elements have been merged; different output
methods may have different default values for an attribute.</p>

<div2>
<head>XML Output Method</head>

<p>The <code>xml</code> output method outputs the result tree as a
well-formed XML external general parsed entity. If the root node of
the result tree has a single element node child and no text node
children, then the entity should also be a well-formed XML document
entity. When the entity is referenced within a trivial XML document
wrapper like this</p>

<eg><![CDATA[
<!DOCTYPE doc [
<!ENTITY e SYSTEM "]]><var>entity-URI</var><![CDATA[">
]>
<doc>&e;</doc>]]></eg>

<p>where <code><var>entity-URI</var></code> is a URI for the entity,
then the wrapper
document as a whole should be a well-formed XML document conforming to
the XML Namespaces Recommendation <bibref ref="XMLNAMES"/>.  In
addition, the output should be such that if a new tree was constructed
by parsing the wrapper as an XML document as specified in <specref
ref="data-model"/>, and then removing the document element, making its
children instead be children of the root node, then the new tree would
be the same as the result tree, with the following possible
exceptions:</p>

<ulist>

<item><p>The order of attributes in the two trees may be
different.</p></item>

<item><p>The new tree may contain namespace nodes that were not
present in the result tree.</p>
<note><p>An XSLT processor may need to add
namespace declarations in the course of outputting the result tree as
XML.</p></note>
</item>

</ulist>

<p>If the XSLT processor generated a document type declaration because
of the <code>doctype-system</code> attribute, then the above
requirements apply to the entity with the generated document type
declaration removed.</p>

<p>The <code>version</code> attribute specifies the version of XML to
be used for outputting the result tree.  If the XSLT processor does
not support this version of XML, it should use a version of XML that
it does support.  The version output in the XML declaration (if an XML
declaration is output) should correspond to the version of XML that
the processor used for outputting the result tree. The value of the
<code>version</code> attribute should match the <xnt
href="&XML;#NT-VersionNum">VersionNum</xnt> production of the XML
Recommendation <bibref ref="XML"/>. The default value is
<code>1.0</code>.</p>

<p>The <code>encoding</code> attribute specifies the preferred
encoding to use for outputting the result tree.  XSLT processors are
required to respect values of <code>UTF-8</code> and
<code>UTF-16</code>.  For other values, if the XSLT processor does not
support the specified encoding it may signal an error; if it does not
signal an error it should use <code>UTF-8</code> or
<code>UTF-16</code> instead.  The XSLT processor must not use an
encoding whose name does not match the <xnt
href="&XML;#NT-EncName">EncName</xnt> production of the XML
Recommendation <bibref ref="XML"/>.  If no <code>encoding</code>
attribute is specified, then the XSLT processor should use either
<code>UTF-8</code> or <code>UTF-16</code>.  It is possible that the
result tree will contain a character that cannot be represented in the
encoding that the XSLT processor is using for output.  In this case,
if the character occurs in a context where XML recognizes character
references (i.e. in the value of an attribute node or text node), then
the character should be output as a character reference; otherwise
(for example if the character occurs in the name of an element) the
XSLT processor should signal an error.</p>

<p>If the <code>indent</code> attribute has the value
<code>yes</code>, then the <code>xml</code> output method may output
whitespace in addition to the whitespace in the result tree (possibly
based on whitespace stripped from either the source document or the
stylesheet) in order to indent the result nicely; if the
<code>indent</code> attribute has the value <code>no</code>, it should
not output any additional whitespace. The default value is
<code>no</code>.  The <code>xml</code> output method should use an
algorithm to output additional whitespace that ensures that the result
if whitespace were to be stripped from the output using the process
described in <specref ref="strip"/> with the set of
whitespace-preserving elements consisting of just
<code>xsl:text</code> would be the same when additional whitespace is
output as when additional whitespace is not output.</p>

<note><p>It is usually not safe to use <code>indent="yes"</code> with
document types that include element types with mixed content.</p></note>

<p>The <code>cdata-section-elements</code> attribute contains a
whitespace-separated list of <xnt
href="&XMLNames;#NT-QName">QName</xnt>s.  Each <xnt
href="&XMLNames;#NT-QName">QName</xnt> is expanded into an
expanded-name using the namespace declarations in effect on the
<code>xsl:output</code> element in which the <xnt
href="&XMLNames;#NT-QName">QName</xnt> occurs; if there is a default
namespace, it is used for <xnt href="&XMLNames;#NT-QName">QName</xnt>s
that do not have a prefix.  The expansion is performed before the
merging of multiple <code>xsl:output</code> elements into a single
effective <code>xsl:output</code> element. If the expanded-name of the
parent of a text node is a member of the list, then the text node
should be output as a CDATA section. For example,</p>

<eg><![CDATA[<xsl:output cdata-section-elements="example"/>]]></eg>

<p>would cause a literal result element written in the stylesheet as</p>

<eg><![CDATA[<example>&lt;foo></example>]]></eg>

<p>or as</p>

<eg>&lt;example>&lt;![CDATA[&lt;foo>]]&gt;&lt;/example></eg>

<p>to be output as</p>

<eg>&lt;example>&lt;![CDATA[&lt;foo>]]&gt;&lt;/example></eg>

<p>If the text node contains the sequence of characters
<code>]]&gt;</code>, then the currently open CDATA section should be
closed following the <code>]]</code> and a new CDATA section opened
before the <code>&gt;</code>. For example, a literal result element
written in the stylesheet as</p>

<eg>&lt;example&gt;]]&amp;gt;&lt;/example&gt;</eg>

<p>would be output as</p>

<eg>&lt;example&gt;&lt;![CDATA[]]]]&gt;&lt;![CDATA[&gt;]]&gt;&lt;/example&gt;</eg>

<p>If the text node contains a character that is not representable in
the character encoding being used to output the result tree, then the
currently open CDATA section should be closed before the character,
the character should be output using a character reference or entity
reference, and a new CDATA section should be opened for any further
characters in the text node.</p>

<p>CDATA sections should not be used except for text nodes that the
<code>cdata-section-elements</code> attribute explicitly specifies
should be output using CDATA sections.</p>

<p>The <code>xml</code> output method should output an XML declaration
unless the <code>omit-xml-declaration</code> attribute has the value
<code>yes</code>. The XML declaration should include both version
information and an encoding declaration. If the
<code>standalone</code> attribute is specified, it should include a
standalone document declaration with the same value as the value as
the value of the <code>standalone</code> attribute.  Otherwise, it
should not include a standalone document declaration; this ensures
that it is both a XML declaration (allowed at the beginning of a
document entity) and a text declaration (allowed at the beginning of
an external general parsed entity).</p>

<p>If the <code>doctype-system</code> attribute is specified, the
<code>xml</code> output method should output a document type
declaration immediately before the first element.  The name following
<code>&lt;!DOCTYPE</code> should be the name of the first element.  If
<code>doctype-public</code> attribute is also specified, then the
<code>xml</code> output method should output <code>PUBLIC</code>
followed by the public identifier and then the system identifier;
otherwise, it should output <code>SYSTEM</code> followed by the system
identifier.  The internal subset should be empty.  The
<code>doctype-public</code> attribute should be ignored unless the
<code>doctype-system</code> attribute is specified.</p>

<p>The <code>media-type</code> attribute is applicable for the
<code>xml</code> output method.  The default value for the
<code>media-type</code> attribute is <code>text/xml</code>.</p>

</div2>

<div2>
<head>HTML Output Method</head>

<p>The <code>html</code> output method outputs the result tree as
HTML; for example,</p>

<eg>&lt;xsl:stylesheet version="1.0"
                xmlns:xsl="&XSLT.ns;"><![CDATA[

<xsl:output method="html"/>

<xsl:template match="/">
  <html>
   <xsl:apply-templates/>
  </html>
</xsl:template>

...

</xsl:stylesheet>]]></eg>

<p>The <code>version</code> attribute indicates the version of the
HTML.  The default value is <code>4.0</code>, which specifies that the
result should be output as HTML conforming to the HTML 4.0
Recommendation <bibref ref="HTML"/>.</p>

<p>The <code>html</code> output method should not output an element
differently from the <code>xml</code> output method unless the

examples/REC-xslt-19991116.xml  view on Meta::CPAN

  (xsl:include
  | xsl:strip-space
  | xsl:preserve-space
  | xsl:output
  | xsl:key
  | xsl:decimal-format
  | xsl:attribute-set
  | xsl:variable
  | xsl:param
  | xsl:template
  | xsl:namespace-alias
  %non-xsl-top-level;)*)
">

<!ENTITY % top-level-atts '
  extension-element-prefixes CDATA #IMPLIED
  exclude-result-prefixes CDATA #IMPLIED
  id ID #IMPLIED
  version NMTOKEN #REQUIRED
  xmlns:xsl CDATA #FIXED "]]>&XSLT.ns;<![CDATA["
  %space-att;
'>

<!-- This entity is defined for use in the ATTLIST declaration
for result elements. -->

<!ENTITY % result-element-atts '
  xsl:extension-element-prefixes CDATA #IMPLIED
  xsl:exclude-result-prefixes CDATA #IMPLIED
  xsl:use-attribute-sets %qnames; #IMPLIED
  xsl:version NMTOKEN #IMPLIED
'>

<!ELEMENT xsl:stylesheet %top-level;>
<!ATTLIST xsl:stylesheet %top-level-atts;>

<!ELEMENT xsl:transform %top-level;>
<!ATTLIST xsl:transform %top-level-atts;>

<!ELEMENT xsl:import EMPTY>
<!ATTLIST xsl:import href %URI; #REQUIRED>

<!ELEMENT xsl:include EMPTY>
<!ATTLIST xsl:include href %URI; #REQUIRED>

<!ELEMENT xsl:strip-space EMPTY>
<!ATTLIST xsl:strip-space elements CDATA #REQUIRED>

<!ELEMENT xsl:preserve-space EMPTY>
<!ATTLIST xsl:preserve-space elements CDATA #REQUIRED>

<!ELEMENT xsl:output EMPTY>
<!ATTLIST xsl:output
  method %qname; #IMPLIED
  version NMTOKEN #IMPLIED
  encoding CDATA #IMPLIED
  omit-xml-declaration (yes|no) #IMPLIED
  standalone (yes|no) #IMPLIED
  doctype-public CDATA #IMPLIED
  doctype-system CDATA #IMPLIED
  cdata-section-elements %qnames; #IMPLIED
  indent (yes|no) #IMPLIED
  media-type CDATA #IMPLIED
>

<!ELEMENT xsl:key EMPTY>
<!ATTLIST xsl:key
  name %qname; #REQUIRED
  match %pattern; #REQUIRED
  use %expr; #REQUIRED
>

<!ELEMENT xsl:decimal-format EMPTY>
<!ATTLIST xsl:decimal-format
  name %qname; #IMPLIED
  decimal-separator %char; "."
  grouping-separator %char; ","
  infinity CDATA "Infinity"
  minus-sign %char; "-"
  NaN CDATA "NaN"
  percent %char; "%"
  per-mille %char; "&#x2030;"
  zero-digit %char; "0"
  digit %char; "#"
  pattern-separator %char; ";"
>

<!ELEMENT xsl:namespace-alias EMPTY>
<!ATTLIST xsl:namespace-alias
  stylesheet-prefix CDATA #REQUIRED
  result-prefix CDATA #REQUIRED
>

<!ELEMENT xsl:template
 (#PCDATA
  %instructions;
  %result-elements;
  | xsl:param)*
>

<!ATTLIST xsl:template
  match %pattern; #IMPLIED
  name %qname; #IMPLIED
  priority %priority; #IMPLIED
  mode %qname; #IMPLIED
  %space-att;
>

<!ELEMENT xsl:value-of EMPTY>
<!ATTLIST xsl:value-of
  select %expr; #REQUIRED
  disable-output-escaping (yes|no) "no"
>

<!ELEMENT xsl:copy-of EMPTY>
<!ATTLIST xsl:copy-of select %expr; #REQUIRED>

<!ELEMENT xsl:number EMPTY>
<!ATTLIST xsl:number
   level (single|multiple|any) "single"
   count %pattern; #IMPLIED



( run in 2.533 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )