blob: 6cc82a472835ef1a8facac2de9e5ea6f80cc1e36 [file] [log] [blame]
<?xml version="1.0" standalone="no"?>
<!DOCTYPE s1 SYSTEM "../../style/dtd/document.dtd">
<!--
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
-->
<s1 title="Extensions library">
<ul>
<li><link anchor="intro">Introduction</link></li>
<li><link anchor="xalanns">Xalan namespace</link></li>
<li><link anchor="nodeset">nodeset</link></li>
<li><link anchor="intersection">intersection</link></li>
<li><link anchor="difference">difference</link></li>
<li><link anchor="distinct">distinct</link></li>
<li><link anchor="evaluate">evaluate</link></li>
<li><link anchor="hassamenodes">hasSameNodes</link></li>
</ul><anchor name="intro"/>
<s2 title= "Introduction">
<p>Extension functions provide a powerful mechanism
for extending and simplifying what you can do with an XLST processor like
Xalan. With input and contributions from the XML open-source developer community, we are working on placing the most useful
extensions in an extensions library distributed with &xslt4c;. If you have ideas and/or contributions you would like to make, please email us at the <human-resource-ref idref="xalandev"/>.</p>
</s2><anchor name="xalanns"/>
<s2 title="Xalan namespace">
<p>We are placing the Xalan extension functions in the XalanExtensions module and we have defined a namespace for this module:</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>http://xml.apache.org/xalan</code></p>
<p>If you are calling &xslt4c;-supplied extensions, we recommend that you define this namespace in your stylesheet element, and call the extension using the namespace prefix that you have associated with that namespace. That way, if we later reorganize how the &xslt4c;-supplied extensions are stored, you won't have to modify your stylesheet.</p>
<p>For an example that uses this namespace, see <link anchor="ex-nodeset">Example with the nodeset extension function</link>.</p>
</s2>
<anchor name="nodeset"/>
<s2 title= "nodeset">
<p>Implemented in <jump href="apidocs/class_functionnodeset.html">FunctionNodeSet</jump>, <code>nodeset (result-tree-fragment)</code> casts a result tree fragment into a node-set.</p>
<note>When you bind a variable to a template, rather than to the value generated by a select expression, the data type of the variable is result tree fragment. For more information, see <jump href="http://www.w3.org/TR/xslt#section-Result-Tree-Fragments">Result Tree Fragments</jump>.</note>
<anchor name="ex-nodeset"/>
<s3 title="Example with the nodeset extension function">
<p>The following stylesheet uses the nodeset extension function to cast a result tree fragment into a node-set that can then be navigated in standard XPath manner. It uses the http://xml.apache.org/xalan namespace to provide access to the nodeset() method in xml.apache.xalan.lib.Extensions.</p>
<source>&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan"&gt;
&lt;xsl:template match="/"&gt;
&lt;out&gt;
&lt;xsl:variable name="rtf"&gt;
&lt;docelem&gt;
&lt;elem1&gt;
&lt;elem1a&gt;ELEMENT1A&lt;/elem1a&gt;
&lt;elem1b&gt;,ELEMENT1B&lt;/elem1b&gt;
&lt;/elem1&gt;
&lt;elem2&gt;
&lt;elem2a&gt;ELEMENT2A&lt;/elem2a&gt;
&lt;/elem2&gt;
&lt;/docelem&gt;
&lt;/xsl:variable&gt;
&lt;xsl:for-each select="xalan:nodeset($rtf)/docelem//*"&gt;
&lt;xsl:value-of select="name(.)"/&gt;&lt;xsl:text&gt;,&lt;/xsl:text&gt;
&lt;/xsl:for-each>
&lt;/out>
&lt;/xsl:template>
&lt;/xsl:stylesheet&gt;</source>
<p>The output of running this stylesheet (with any XML input source) is a comma-delimited list of the element names in the node-set<br/>
&nbsp;&nbsp;<code>&lt;out&gt;elem1,elem1a,elem1b,elem2,elem2a&lt;/out&gt;</code></p>
<note>For illustration purposes, the preceding stylesheet pays no attention to the structure and content of the XML input document. Instead, it processes the template (in the stylesheet) bound to the variable named rtf.</note>
</s3>
</s2><anchor name="intersection"/>
<s2 title="intersection">
<p>Implemented in <jump href="apidocs/class_functionintersection.html">FunctionIntersection</jump>, <code>intersection (node-set1, node-set2)</code> returns a node-set with all nodes that are in ns1 and in ns2.</p>
</s2><anchor name="difference"/>
<s2 title= "difference">
<p>Implemented in <jump href="apidocs/class_functiondifference.html">FunctionDifference</jump>, <code>difference(node-set1, node-set2)</code> returns a node-set with the nodes in node-set1 and not in node-set2.</p>
</s2><anchor name="distinct"/>
<s2 title= "distinct">
<p>Implemented in <jump href="apidocs/class_functiondistinct.html">FunctionDistinct</jump>, distinct (node-set) returns a node-set containing nodes with distinct string values. If more than one node in the node-set
contains the same text node value, distinct only returns the first of these nodes that it finds.</p>
</s2><anchor name="evaluate"/>
<s2 title= "evaluate">
<p>Implemented in <jump href="apidocs/class_functionevaluate.html">FunctionEvaluate</jump>, <code>evaluate (xpath-expression)</code> returns the result of evaluating the xpath-expression in the current
XPath expression context (automatically passed in by the extension mechanism).</p>
<p>Use the evaluation extension function when the value of the expression is not known until run time.</p>
</s2>
<anchor name="hassamenodes"/>
<s2 title= "hasSameNodes">
<p>Implemented in <jump href="apidocs/class_functionhassamenodes.html">FunctionHasSameNodes</jump>, <code>hasSameNodes(node-set1, node-set2)</code> returns true if both node-set1 and node-set2 contain exactly the same set of nodes.</p>
</s2>
</s1>