NCBI C++ ToolKit
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
xslt::stylesheet Class Reference

Search Toolkit Book for xslt::stylesheet

The xslt::stylesheet class is used to hold information about an XSLT stylesheet. More...

#include <misc/xmlwrapp/stylesheet.hpp>

+ Collaboration diagram for xslt::stylesheet:

Public Types

typedef stylesheet_param param_type
 Type for passing parameters to the stylesheet. More...
 

Public Member Functions

 stylesheet (const char *filename)
 Create a new xslt::stylesheet object and load and parse the stylesheet in the given filename. More...
 
 stylesheet (const xml::document &doc)
 Create a new xslt::stylesheet object from an xml::document object that contains the parsed stylesheet. More...
 
 stylesheet (const char *data, size_t size)
 Create a new xslt::stylesheet object by parsing the given XML from a memory buffer. More...
 
 stylesheet (std::istream &stream)
 Create a new xslt::stylesheet object by parsing the given XML from a stream. More...
 
void register_extension_function (extension_function *ef, const char *name, const char *uri, xml::ownership_type ownership=xml::type_not_own)
 Register an XSLT extension function. More...
 
void register_extension_element (extension_element *ee, const char *name, const char *uri, xml::ownership_type ownership=xml::type_not_own)
 Register an XSLT extension element. More...
 
virtual ~stylesheet (void)
 Clean up after an xslt::stylesheet. More...
 
 stylesheet (stylesheet &&other)
 Moving constructor. More...
 
stylesheetoperator= (stylesheet &&other)
 Moving assignment. More...
 
xml::document_proxy apply (const xml::document &doc, xml::error_messages *messages_=NULL)
 Apply this stylesheet to the given XML document. More...
 
xml::document_proxy apply (const xml::document &doc, const param_type &with_params, xml::error_messages *messages_=NULL)
 Apply this stylesheet to the given XML document. More...
 

Private Member Functions

void attach_refcount (void)
 
void destroy (void)
 
 stylesheet (const stylesheet &)
 
stylesheetoperator= (const stylesheet &)
 

Private Attributes

impl::stylesheet_implpimpl_
 

Detailed Description

The xslt::stylesheet class is used to hold information about an XSLT stylesheet.

You can use it to load in a stylesheet and then use that stylesheet to transform an XML document to something else.

Definition at line 130 of file stylesheet.hpp.

Member Typedef Documentation

◆ param_type

Type for passing parameters to the stylesheet.

Definition at line 133 of file stylesheet.hpp.

Constructor & Destructor Documentation

◆ stylesheet() [1/6]

xslt::stylesheet::stylesheet ( const char *  filename)
explicit

Create a new xslt::stylesheet object and load and parse the stylesheet in the given filename.

Parameters
filenameThe name of the file that contains the stylesheet.
Author
Peter Jones

Definition at line 465 of file stylesheet.cpp.

References xml::document::get_doc_data(), xml::error_messages::get_messages(), xml::document::release_doc_data(), xml::error_message::type_error, and xml::type_warnings_not_errors.

◆ stylesheet() [2/6]

xslt::stylesheet::stylesheet ( const xml::document doc)
explicit

Create a new xslt::stylesheet object from an xml::document object that contains the parsed stylesheet.

The given xml::document is copied. This is needed because the stylesheet will own the document and free it.

Parameters
docThe parsed stylesheet.
Author
Peter Jones

Definition at line 498 of file stylesheet.cpp.

References xml::document::get_doc_data(), xml::error_messages::get_messages(), xml::document::release_doc_data(), and xml::error_message::type_error.

◆ stylesheet() [3/6]

xslt::stylesheet::stylesheet ( const char *  data,
size_t  size 
)

Create a new xslt::stylesheet object by parsing the given XML from a memory buffer.

Parameters
dataThe XML memory buffer.
sizeSize of the memory buffer.
Author
Denis Vakatov

Definition at line 529 of file stylesheet.cpp.

References data, xml::document::get_doc_data(), xml::error_messages::get_messages(), xml::document::release_doc_data(), ncbi::grid::netcache::search::fields::size, xml::error_message::type_error, and xml::type_warnings_not_errors.

◆ stylesheet() [4/6]

xslt::stylesheet::stylesheet ( std::istream &  stream)

Create a new xslt::stylesheet object by parsing the given XML from a stream.

Parameters
streamStream to read from
Author
Denis Vakatov

Definition at line 560 of file stylesheet.cpp.

References xml::document::get_doc_data(), xml::error_messages::get_messages(), xml::document::release_doc_data(), xml::error_message::type_error, and xml::type_warnings_not_errors.

◆ ~stylesheet()

xslt::stylesheet::~stylesheet ( void  )
virtual

Clean up after an xslt::stylesheet.

Author
Peter Jones

Definition at line 680 of file stylesheet.cpp.

References destroy().

◆ stylesheet() [5/6]

xslt::stylesheet::stylesheet ( stylesheet &&  other)

Moving constructor.

Parameters
otherThe other stylesheet.

Definition at line 686 of file stylesheet.cpp.

References NULL.

◆ stylesheet() [6/6]

xslt::stylesheet::stylesheet ( const stylesheet )
private

Member Function Documentation

◆ apply() [1/2]

xml::document_proxy xslt::stylesheet::apply ( const xml::document doc,
const param_type with_params,
xml::error_messages messages_ = NULL 
)

Apply this stylesheet to the given XML document.

The results document is returned. If there is an error during transformation, this function will throw an xml::exception exception.

Attention
The method is not thread safe
Note
The xslt output method is taken into account when the result document is saved later into a string or a stream as in (e.g. to suppress XML declaration): mydoc.save_to_string(mystring, xml::save_op_no_decl); The formatting flags are taken into consideration only if the xslt output method is xml. (The xslt default output method is xml).
Parameters
docThe XML document to transform.
with_paramsOverride xsl:param elements using the given key/value map
messages_A pointer to the object where the error messages are collected. If NULL is passed then no messages will be collected. In case of errors an exception is thrown anyway.
Note
each (simple) param name must be enclosed in quotes as per libxslt specs
string parameter value has to be enclosed in quotes. e.g.,
params["ParamString"] = "'Text'";
each xpath parameter value (including simple numerics) should be given as is. e.g.
params["ParamXpath"] = "//NodeName";
params["ParamNumber"] = "123565";
Returns
The result tree.

Definition at line 717 of file stylesheet.cpp.

References xml::document::get_doc_data_read_only(), and input().

◆ apply() [2/2]

xml::document_proxy xslt::stylesheet::apply ( const xml::document doc,
xml::error_messages messages_ = NULL 
)

Apply this stylesheet to the given XML document.

The results document is returned. If there is an error during transformation, this function will throw an xml::exception exception.

Attention
The method is not thread safe
Note
The xslt output method is taken into account when the result document is saved later into a string or a stream as in (e.g. to suppress XML declaration): mydoc.save_to_string(mystring, xml::save_op_no_decl); The formatting flags are taken into consideration only if the xslt output method is xml. (The xslt default output method is xml).
Parameters
docThe XML document to transform.
messages_A pointer to the object where the error messages are collected. If NULL is passed then no messages will be collected. In case of errors an exception is thrown anyway.
Returns
The result tree.

Definition at line 704 of file stylesheet.cpp.

References xml::document::get_doc_data_read_only(), input(), and NULL.

◆ attach_refcount()

void xslt::stylesheet::attach_refcount ( void  )
private

Definition at line 451 of file stylesheet.cpp.

References xslt::impl::stylesheet_refcount::inc_ref().

◆ destroy()

void xslt::stylesheet::destroy ( void  )
private

Definition at line 656 of file stylesheet.cpp.

References xslt::impl::destroy_stylesheet(), NULL, and xml::type_own.

◆ operator=() [1/2]

stylesheet& xslt::stylesheet::operator= ( const stylesheet )
private

◆ operator=() [2/2]

xslt::stylesheet & xslt::stylesheet::operator= ( stylesheet &&  other)

Moving assignment.

Parameters
otherThe other stylesheet.

Definition at line 693 of file stylesheet.cpp.

References destroy(), and NULL.

◆ register_extension_element()

void xslt::stylesheet::register_extension_element ( extension_element ee,
const char *  name,
const char *  uri,
xml::ownership_type  ownership = xml::type_not_own 
)

Register an XSLT extension element.

Parameters
efThe extension element pointer.
nameExtension element name. It cannot be NULL.
uriExtension element URI. It cannot be NULL.
ownershipIf owned then xslt::stylesheet is responsible for deleting the extension element. The responsibility starts from the moment this member is called, i.e. even if the registration failed the extension element will be deleted.
Exceptions
Throwxslt::exception in case of problems
Author
Denis Vakatov, NCBI

Definition at line 624 of file stylesheet.cpp.

References ncbi::grid::netcache::search::fields::key, NULL, string, and xml::type_own.

◆ register_extension_function()

void xslt::stylesheet::register_extension_function ( extension_function ef,
const char *  name,
const char *  uri,
xml::ownership_type  ownership = xml::type_not_own 
)

Register an XSLT extension function.

Parameters
efThe extension function pointer.
nameExtension function name. It cannot be NULL.
uriExtension function URI. It cannot be NULL.
ownershipIf owned then xslt::stylesheet is responsible for deleting the extension function. The responsibility starts from the moment this member is called, i.e. even if the registration failed the extension function will be deleted.
Exceptions
Throwxslt::exception in case of problems
Author
Denis Vakatov, NCBI

Definition at line 591 of file stylesheet.cpp.

References ncbi::grid::netcache::search::fields::key, NULL, string, and xml::type_own.

Member Data Documentation

◆ pimpl_

impl::stylesheet_impl* xslt::stylesheet::pimpl_
private

Definition at line 302 of file stylesheet.hpp.


The documentation for this class was generated from the following files:
Modified on Wed Jul 17 13:20:57 2024 by modify_doxy.py rev. 669887