Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Transformer Management

hunterhacker edited this page Nov 29, 2011 · 15 revisions

Content Transformer Management

The majority of the time content is stored in a format that isn't suitable for rendering. Content transformers allow the results from the string query service, key/value service, structured queries or the data store to be transformed into a different format (eg: HTML) before being returned.

Transformers can be written using either XSLT or XQuery. XSLT transformers will be passed the content as the context node and XQuery based transformers can access the content via a $content external variable. Neither XSLT or XQuery transformers can perform any updates to the database. Doing so will raise an error.

Store a transformer

Stores a transform to the given name. This name is then used in various services via the applyTransform paramater. If a transformer already exists with this name, it's overwritten with the new transformer.

  • Endpoint: /manage/transformer/<transformer-name>
  • Request type: PUT
  • Request body: The XSLT or XQuery should be sent as the request body
  • Returns:
    • If the transformer was successfully stored, a 200 is returned with an empty response body
    • If there was an error parsing the XSLT or evaluating the XQuery, a 400 is returned
  • Examples:
    • /manage/transformer/toHTML

Get a list of all configured transformers

To get a list of all the transformers that are configured, make a GET request to:

/manage/transformers

Get the contents of the transformer

Returns the transformer that is stored under the given name.

  • Endpoint: /manage/transformer/<transformer-name>
  • Request type: GET
  • Returns:
    • If the transformer exists, a 200 is returned with the response body being the transformer itself
    • If the transformer does not exist, a 404 is returned
  • Example:
    • /manage/transformer/toHTML

Sample response

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            <body>
            …
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

Delete a transformer

Removes the transformer.

  • Endpoint: /manage/transformer/<transformer-name>
  • Request type: DELETE
  • Returns:
    • If the transformer was deleted, a 200 is returned with an empty response body.
    • If the transformer does not exist, a 404 is returned
  • Example:
    • /manage/transformer/toHTML

Discussion

When it comes to errors in the XSLT, is it checked for well-formedness or validity as XSLT? Checks that it's well-formed and in the XSLT namespace. If not, you get a 400 error.

If there's an XSLT parse error will it be described in the 400 response body? Hope so. Should verify.

Is the transformer name limited to alphanumeric without a leading decimal? Nope, can be anything that doesn't contain a forward slash. Probably we should apply the same rules as for other names.

Should include sample XSLT and XQuery transformers.

Clone this wiki locally