Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Apache License, Version 2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Table of Contents
The index lists all the ServingXML elements in alphabetical order.
The chapters group them by functional area.
| Name | Required | Value | Description |
|---|---|---|---|
| id | No | QName | An identifier of an element instance. This id is the target for references by ref attributes. |
| ref | No | QName | This attribute is used to reference an id. |
The resources defined in a resources script may be given ids and referred to by reference, as shown below.
Figure 1.1. SAX pipeline with references
<sx:resources xmlns:sx="http://www.servingxml.com/core">
<sx:service id="myPipeline">
<sx:serialize>
<sx:transform>
<sx:filter ref="myPreFilter"/>
<sx:filter ref="myFilter"/>
<sx:filter ref="myPostFilter"/>
</sx:transform>
</sx:serialize>
</sx:service>
<sx:saxFilter id="myPreFilter" class="PreFilter"/>
<sx:xslt id="myFilter">
<sx:urlSource url="filter.xsl"/>
</sx:xslt>
<sx:saxFilter id="myPostFilter" class="PostFilter"/>
</sx:resources>
Note that we could have written <sx:saxFilter ref="myPreFilter"/>,
but instead we wrote <sx:filter ref="myPreFilter"/>,
substituting the abstract component sx:filter for the derived sx:saxFilter.
Identifiers given to components must be unique up to
the abstract component level, for instance, a service and a filter may both be named "myPipeline",
but a sx:saxFilter and a sx:xslt must be identified differently.
| Name | Required | Value | Description |
|---|---|---|---|
| revalidate | No | string | A list of revalidation codes with possible values "synch" or "asynch" (or both), or "full" or "none". |
| Name | Required | Value | Description |
|---|---|---|---|
| class | Yes | Java class | An implementation of the com.servingxml.components.regex.PatternMatcher interface. |
| Name | Required | Value | Description |
|---|---|---|---|
| version | No | XSLT version | The value of the XSLT version attribute appearing in generated stylesheets. Defaults to "1.0" |
Optionally, any number of sx:outputProperty elements.
Optionally, any number of sx:systemProperty elements.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| value | No | SubstitutionExpr | A string value that may contain a parameter inside curly braces, e.g. "{$my-param}.xml". |
| select | No | XPath expression | An XPath expression evaluated against the default XML document. |
The sx:defaultValue element is used in a sx:parameter element to define a
default value for a parameter.
The default value may be specified either by a value attribute
or by the content. This value is only a default value, and if a run-time parameter is passed with the
same name, the run-time value will be used in place of the default value.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. |
Example 3.2. Apply a stylesheet to a fault raised in the book-order document handler.
<sx:service id="post-book-order">
<sx:serialize>
<sx:transform>
<sx:content ref="myns:book-order"/>
<sx:xslt ref="myns:confirm-order"/>
</sx:transform>
<sx:onError>
<sx:transform>
<sx:xslt ref="myns:book-order"/>
</sx:transform>
</sx:onError>
</sx:serialize>
</sx:service>
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| name | Yes | QName | The name of the parameter. |
| value | No | SubstitutionExpr | A string value that may reference a parameter or field name inside curly braces, e.g. "{$my-param}.xml". |
| select | No | XPath expression | An XPath expression evaluated against the default XML document. |
| type | No | XML Schema types | The parameter value type. Defaults to xs:string The input parameter values will be converted to this type
if required. |
The sx:parameter element is used to define a parameter as a QName-value pair,
for example,
<sx:parameter name="validate">no</sx:parameter>
The value of the parameter may be specified either by a value attribute
or by the content.
A parameter defined inside an element is visible to all siblings and all their descendents. It is not visible to ancestors. If the parameter has the same QName as a parameter in an ancestor, a new parameter value replaces the old one within the scope of siblings and descendents, but not in the scope of ancestors, the old value is still visible to ancestors. It is not possible to change the parameter value of an ancestor, changes are visible to siblings and descendents only. This is to avoid side effects.
The application processing the resources script may pass additional parameters to the
script. For example, the console app may pass the parameter validate like this:
java -jar dir/servingxml.jar -r resources.xml myPipeline validate=yes
< input.xml > output.xml
If you want to define a default value for the parameter, you must do so with
a sx:defaultValue element as follows.
<sx:parameter name="validate"><sx:defaultValue>no</sx:defaultValue></sx:parameter>
A passed parameter cannot override a parameter defined in a resources script unless
the script's value is a default value, enclosed by a sx:defaultValue element.
More generally, a parameter in an ancestor cannot override a parameter in a descendent
unless the descendant's value is a default value.
Example 3.3. Example of initializing a parameter to a constant.
<sx:parameter name="validate">yes</sx:parameter>
Example 3.4. Example of initializing a parameter with the output of a transformation.
<sx:parameter name="myParam">
<sx:serialize>
<sx:transform>
<sx:xslt>
<sx:urlSource url="styles/transform1.xsl"/>
</sx:xslt>
<sx:content ref="flat1"/>
</sx:transform>
</sx:serialize>
</sx:parameter>
Example 3.5. Example of initializing a parameter using regular expression substitution on a record field called "name"
<sx:parameter name="output-file-name">
<sx:replace match="(books.*)[.]txt" replaceWith ="$1-new.txt"><sx:toString value="{name}"/></sx:replace>
</sx:parameter>
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| key | Yes | String | Deprecated - use name instead. |
| name | Yes | String | The custom property name. |
| value | Yes | String | The custom property value. |
| Name | Required | Value | Description |
|---|---|---|---|
| ns | No | URI | The default namespace for the pages, documents, styles and serializers defined in this resources script. |
The list of elements that may be defined with a qualified name at the top level of the resources script includes all the elements that are defined in the sx:instructions section of the servingxml.xml configuration file. These include
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| service | Yes | SubstitutionExpr | An expression that evaluates to a QName identifying a service. |
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. |
Example 3.6. Books page.
<sx:service id="books">
<sx:serialize>
<sx:transform>
<sx:content ref="myns:books"/>
<sx:xslt ref="myns:books"/>
</sx:transform>
</sx:serialize>
</sx:service>
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| key | Yes | String | Deprecated - use name instead. |
| name | Yes | String | The system property name. |
| value | Yes | String | The value of a system property. |
| Name | Required | Value | Description |
|---|---|---|---|
| ref | Yes | QName | This attribute is used to reference the id of a task. |
This is an abstract element that allows us to refer generically to any specialization of
sx:task, such as sx:transform.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. |
A sx:raiseError element results in an exception being thrown.
It is usually used inside an sx:onError element.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| separator | No | char | A separator to separate each string value in the content. |
| quoteSymbol | No | char | A symbol to surround each string value. |
Any number of sx:string elements.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| fromFormat | Yes | String | The format of the input string, which must must follow the syntax specified for the JDK SimpleDateFormat class. |
| toFormat | No | String | The format of the output string, which must must follow the syntax specified for the JDK SimpleDateFormat class. Defaults to the date format for the default locale. |
An input string in the fromFormat, or a sx:string element that
evaluates to an input string in the fromFormat. If the input
string is empty, an empty (null) value is produced.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| format | Yes | String | The format of the input string, which must must follow the syntax specified for the JDK SimpleDateFormat class. |
| inputTimezone | Yes | String | The format of the input string, which must must follow the syntax specified for the JDK SimpleDateFormat class. |
Lexical representation of one the eight XML Schema date/time datatypes, or an sx:string element that evaluates to a lexical representation. If the input string is empty, an empty (null) value is produced.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. |
The current date is output as a string with a lexical representation as defined for xs:date of XML Schema Part 2: Datatypes.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. |
The current date is output as a string with a lexical representation as defined for xs:dateTime of XML Schema Part 2: Datatypes.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. |
The current time is output as a string with a lexical representation as defined for xs:time of XML Schema Part 2: Datatypes.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| format | No | String | The format of the output string, which must must follow the syntax specified for the JDK SimpleDateFormat class. Defaults to the date format for the default locale. |
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| format | No | String | The format of the output string, which must must follow the syntax specified for the JDK SimpleDateFormat class. Defaults to the date format for the default locale. |
Lexical representation of one the eight XML Schema date/time datatypes, or an sx:string element that evaluates to a lexical representation.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| match | No | Regex | Match the entire input string against this pattern. |
| searchFor | No | Regex | Match sub-sequences of the input string against this pattern. |
| replaceWith | Yes | String | Replace all matches with this expression. Dollar signs ($) may be used as references to captured subsequences in the match regular expression, and backslashes (\) may be used to escape literal characters. |
An input string, or a sx:string element that evaluates to an input string.
The sx:replace element applies a regular expression to its content,
and replaces matched content with a replacement string. The value of the regular expression
may be defined either by the match attribute, which attempts to match the
entire content, or by the searchFor attribute,
which searches for all subsequences in the content that match the pattern
Example 4.1. Fix date.
In this example, you have an input record with a field service_from_date, which has the value
2005-06-28 00:00:00
You want to change it to
20050628
You can make the replacement with the sx:replace element as follows.
<sx:replace match="([0-9]{4})-([0-9]{2})-([0-9]{2})(.*)" replaceWith="$1$2$3">
<sx:toString value="{service_from_date}"/>
</sx:replace>
Example 4.2. Remove commas from amount.
In this example, you have an input record with a field PLAN_IT_COST, which has the value
2,500,300.00
You want to change it to
2500300.00
You can make the replacement with the sx:replace element as follows.
<sx:replace searchFor="," replaceWith ="">
<sx:toString value="{PLAN_IT_COST}"/>
</sx:replace>
| Name | Required | Value | Description |
|---|---|---|---|
| ref | Yes | QName | This attribute is used to reference the id of a string. |
This is an abstract element that allows us to refer generically to any specialization of
sx:string, such as sx:toString.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| value | No | SubstitutionExpr | A string value that may contain one or more parameters enclosed in curly braces, e.g. "{$my-param}.xml". |
| separator | No | char | A separator to separate the pieces if the expression resolves to multiple values. |
| quoteSymbol | No | char | A symbol to surround the pieces. Deprecated, use a sx:quoteSymbol child element instead. |
Optionally, a sx:quoteSymbol element, to specify a quote symbol to surround the pieces making up the string.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| encoding | No | String | A charset name. If a charset is not supplied,
the default will be the charset of the default sink, e.g., the platform's
default charset if the default sink is a flat file supplied to the command line app with the -o option.
|
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| encoding | No | String | A charset name. If an charset is not supplied,
the default will be the charset of the default source, e.g., the platform's
default charset if the default source is a flat file supplied to the command line app with the -i option.
|
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| directory | No | SubstitutionExpr | An optional directory name. |
| file | Yes | SubstitutionExpr | The name of the output file, may contain parameters in the form {$myParam}. |
| encoding | No | String | A charset name. If the output is XML, and a charset is not supplied,
the XML serializer will use the last encoding encountered in the output properties of the transformation pipeline.
If the output is a flat file, and a charset is not supplied, the default will be the platform's default charset.
|
Example 5.1. Example of file sink.
<sx:resources xmlns:sx="http://www.servingxml.com/core">
<sx:service id="books">
<sx:serialize>
<sx:xsltSerializer>
<sx:fileSink file="books.xml"/>
</sx:xsltSerializer>
<sx:transform>
<sx:content ref="books"/>
</sx:transform>
</sx:serialize>
</sx:service>
<sx:document id="books">
<sx:urlSource url="documents/books.xml"/>
</sx:document>
</sx:resources>
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| directory | No | SubstitutionExpr | An optional directory name. |
| file | Yes | SubstitutionExpr | The name of the input file, may contain parameters in the form {$myParam}. |
| encoding | No | String | A charset name. If the input is XML, and a charset is not supplied,
the XML parser will use the encoding specified by the XML declaration. If the input is a
flat file, and a charset is not supplied, the default will be the platform's default charset.
|
Example 5.2. Example of file source.
<sx:resources xmlns:sx="http://www.servingxml.com/core">
<sx:service id="books">
<sx:serialize>
<sx:transform>
<sx:document>
<sx:fileSource file="books.xml"/>
</sx:document>
</sx:transform>
</sx:serialize>
</sx:service>
</sx:resources>
| Name | Required | Value | Description |
|---|---|---|---|
| ref | Yes | QName | This attribute is used to reference the id of a stream sink. |
This is an abstract element that allows us to refer generically to any specialization of
sx:streamSink, sx:fileSink.
| Name | Required | Value | Description |
|---|---|---|---|
| ref | No | QName | This attribute is used to reference the id of a stream source. |
This is an abstract element that allows us to refer generically to any specialization of
sx:streamSource, such as sx:fileSource.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| url | Yes | SubstitutionExpr | The name of the input url, may contain parameters in the form {$myParam}. |
| encoding | No | String | A charset name. If the input is XML, and a charset is not supplied,
the XML parser will use the encoding specified by the XML declaration. If the input is a
flat file, and a charset is not supplied, the default will be the platform's default charset.
|
Example 5.3. Example of url source.
<sx:resources xmlns:sx="http://www.servingxml.com/core">
<sx:service id="books">
<sx:serialize>
<sx:transform>
<sx:document>
<sx:urlSource url="books.xml"/>
</sx:document>
</sx:transform>
</sx:serialize>
</sx:service>
</sx:resources>
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| attribute | Yes | SubstitutionExpr | The name of an attribute to insert into a parent element. The attribute name may contain a field name within curly braces, which will evaluate to the value of the field. The result must evaluate to a QName. |
| select | No | XPath expression | Apply an XPath expression to the elements in the XML representation of a record that satisfy the conditon of the match pattern.
The expression is evaluated as a string.
|
| value | No | SubstitutionExpr | Express the attribute value as a literal value, which may contain parameter names and field names enclosed in curly braces. The result must evaluate to a QName. |
Optionally, any number of sx:string elements. If present, these are used in place of the
value and select attributes.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| path | Yes | SAXPath | A SAXPath expression, which identifies subtrees. |
| batchSize | Yes | Integer | The number of subtrees in a batch. |
| maxFiles | No | Integer | The maximum number of batch files. |
Example 6.1. Writing out countries XML with a maximum of 50 countries to a batch.
<sx:serialize>
<sx:transform>
<sx:content ref="countries"/>
</sx:transform>
<sx:batchedSerializer path="country" batchSize="50">
<sx:xsltSerializer>
<sx:fileSink file="output/countries-{$sx:batchSequenceNumber}.xml"/>
</sx:xsltSerializer>
</sx:batchedSerializer>
</sx:serialize>
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. |
This is an abstract element that allows us to refer generically to any specialization of
sx:content, such as sx:document.
Example 6.2. Using a sx:content element to refer to dynamic content.
<sx:resources xmlns:sx="http://www.servingxml.com/core">
<sx:service id="books">
<sx:serialize>
<sx:transform>
<sx:content ref="books"/>
<sx:xslt ref="books"/>
</sx:transform>
</sx:serialize>
</sx:service>
<sx:dynamicContent name="books" class="samples.books.BookCatalog">
<sx:key>
<sx:keyField name="category"/>
</sx:key>
</sx:dynamicContent>
</sx:resources>
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| class | Yes | Java Class | The name of a Java class that implements com.servingxml.io.saxsink.SaxSink. |
Example 6.3. Defining an Apache fop emitter.
<sx:customSerializer id="fop-serializer"
class="com.servingxml.extensions.fop.xmlpipeline.FopEmitter">
</sx:customSerializer>
Example 6.4. Serializing an xsl-fo XML tree with an Apache fop serializer to produce pdf.
<sx:service id="pulp">
<sx:serialize>
<sx:saxSink ref="myns:fop-serializer"/>
<sx:transform>
<sx:content ref="myns:pulp"/>
<sx:xslt ref="myns:novel-fo"/>
</sx:transform>
</sx:serialize>
</sx:service>
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. |
Example 6.5. Defining a document with reference to an XML file.
<sx:resources xmlns:sx="http://www.servingxml.com/core">
<sx:document id="countries">
<sx:urlSource url="documents/countries.xml"/>
</sx:document>
</sx:resources>
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| wrapWith | No | SubstitutionExpr | Wrap all documents with this root element, defaults to "result". |
This instruction allows you to read a collection of XML documents on a file system as a sequence of documents wrapped with a root element. The results are streamed so that an arbitrarily large number of files may be processed.
Example 6.6. Defining a sequence of XML documents wrapped with the default root element "result".
This example uses an sx:directoryReader element to read the names of the files in a directory called "data", and an sx:document element to load each of the files.
<sx:documentSequence>
<sx:directoryReader directory="data"/>
<sx:document>
<sx:fileSource directory="{parentDirectory}" file="{name}"/>
</sx:document>
</sx:documentSequence>
Example 6.7. Defining a sequence of XML documents wrapped with the root element "documents".
Note that an sx:recordStream element is also subtitutable for a sx:recordReader, which allows additional filtering on the contents of the file system. An sx:transform element is likewise subtitutable for a sx:content, which allows additional transformation and validation of the individual documents.
<sx:documentSequence wrapWith="documents">
<sx:recordStream>
<sx:directoryReader directory="data"/>
<sx:restrictRecordFilter>
<sx:fieldRestriction field="name" pattern="countries.*[.]xml"/>
</sx:restrictRecordFilter>
</sx:recordStream>
<sx:transform>
<sx:document>
<sx:fileSource directory="{parentDirectory}" file="{name}"/>
</sx:document>
<msv:schemaValidator>
<sx:urlSource url="data/countries.xsd"/>
</msv:schemaValidator>
</sx:transform>
</sx:documentSequence>
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| class | Yes | Java Class | The name of a Java class that implements com.servingxml.components.content.dynamic.RequestHandler and, optionally, com.servingxml.components.content.dynamic.Cacheable. |
Example 6.8. Defining a document with reference to a Java class that simulates a SAX parser.
<sx:resources xmlns:sx="http://www.servingxml.com/core">
<sx:dynamicContent name="books" class="samples.books.BookCatalog">
<sx:key>
<sx:keyField name="category"/>
</sx:key>
</sx:dynamicContent>
</sx:resources>
| Name | Required | Value | Description |
|---|---|---|---|
| ref | Yes | QName | This attribute is used to reference an id. |
This is an abstract element that allows us to refer generically to any specialization of
sx:saxSink e.g. sx:xsltSerializer.
This is an abstract element that allows us to refer generically to any specialization of
sx:filter, such as sx:xslt.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. |
See sx:dynamicContent.
| Name | Required | Value | Description |
|---|---|---|---|
| id ref attributes | No | Common id ref attributes. | |
| name | No | Name | Reference to the name of a parameter. On a request, t |