xmlwrapp
Lightweight C++ XML parsing library
Public Types | Public Member Functions | List of all members
xslt::stylesheet Class Reference

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

#include <stylesheet.h>

Public Types

typedef std::map< std::string, std::string > param_type
 Type for passing parameters to the stylesheet. More...
 

Public Member Functions

 stylesheet (const char *filename, xml::error_handler &on_error=xml::throw_on_error)
 Create a new xslt::stylesheet object and load and parse the stylesheet in the given filename. More...
 
 stylesheet (xml::document doc, xml::error_handler &on_error=xml::throw_on_error)
 Create a new xslt::stylesheet object from an xml::document object that contains the parsed stylesheet. More...
 
 ~stylesheet ()
 Clean up after an xslt::stylesheet. More...
 
bool apply (const xml::document &doc, xml::document &result)
 Apply this stylesheet to the given XML document. More...
 
bool apply (const xml::document &doc, xml::document &result, const param_type &with_params)
 Apply this stylesheet to the given XML document. More...
 
bool apply (const xml::document &doc, xml::document &result, xml::error_handler &on_error)
 Apply this stylesheet to the given XML document. More...
 
bool apply (const xml::document &doc, xml::document &result, const param_type &with_params, xml::error_handler &on_error)
 Apply this stylesheet to the given XML document. More...
 
xml::documentapply (const xml::document &doc, xml::error_handler &on_error=xml::throw_on_error)
 Apply this stylesheet to the given XML document. More...
 
xml::documentapply (const xml::document &doc, const param_type &with_params, xml::error_handler &on_error=xml::throw_on_error)
 Apply this stylesheet to the given XML document. More...
 
const std::string & get_error_message () const
 If you used one of the xslt::stylesheet::apply member functions that return a bool, you can use this function to get the text message for the transformation error. More...
 

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.

Member Typedef Documentation

◆ param_type

typedef std::map<std::string, std::string> xslt::stylesheet::param_type

Type for passing parameters to the stylesheet.

Constructor & Destructor Documentation

◆ stylesheet() [1/2]

xslt::stylesheet::stylesheet ( const char *  filename,
xml::error_handler on_error = xml::throw_on_error 
)
explicit

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

Errors are handled by on_error handler; by default, xml::exception is thrown on errors. If there's a fatal error that prevents the stylesheet from being loaded and the error handler doesn't throw an exception, the constructor will throw xml::exception anyway.

Parameters
filenameThe name of the file that contains the stylesheet.
on_errorHandler called to process errors and warnings (since 0.7.0).

◆ stylesheet() [2/2]

xslt::stylesheet::stylesheet ( xml::document  doc,
xml::error_handler on_error = xml::throw_on_error 
)
explicit

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

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

Errors are handled by on_error handler; by default, xml::exception is thrown on errors. If there's a fatal error that prevents the stylesheet from being loaded and the error handler doesn't throw an exception, the constructor will throw xml::exception anyway.

Parameters
docThe parsed stylesheet.
on_errorHandler called to process errors and warnings (since 0.7.0).

◆ ~stylesheet()

xslt::stylesheet::~stylesheet ( )

Clean up after an xslt::stylesheet.

Member Function Documentation

◆ apply() [1/6]

bool xslt::stylesheet::apply ( const xml::document doc,
xml::document result 
)

Apply this stylesheet to the given XML document.

The result document is placed in the second document parameter.

Parameters
docThe XML document to transform.
resultThe result tree after applying this stylesheet.
Returns
True if the transformation was successful and the results placed in result.
False if there was an error, result is not modified.
Deprecated:
Use the form that takes xml::error_handler argument.

◆ apply() [2/6]

bool xslt::stylesheet::apply ( const xml::document doc,
xml::document result,
const param_type with_params 
)

Apply this stylesheet to the given XML document.

The result document is placed in the second document parameter.

Parameters
docThe XML document to transform.
resultThe result tree after applying this stylesheet.
with_paramsOverride xsl:param elements using the given key/value map
Returns
True if the transformation was successful and the results placed in result.
False if there was an error, result is not modified.
Deprecated:
Use the form that takes xml::error_handler argument.

◆ apply() [3/6]

bool xslt::stylesheet::apply ( const xml::document doc,
xml::document result,
xml::error_handler on_error 
)

Apply this stylesheet to the given XML document.

The result document is placed in the second document parameter.

Parameters
docThe XML document to transform.
resultThe result tree after applying this stylesheet.
on_errorHandler called to process errors and warnings (since 0.7.0).
Returns
True if the transformation was successful and the results placed in result.
False if there was an error, result is not modified.

◆ apply() [4/6]

bool xslt::stylesheet::apply ( const xml::document doc,
xml::document result,
const param_type with_params,
xml::error_handler on_error 
)

Apply this stylesheet to the given XML document.

The result document is placed in the second document parameter.

Parameters
docThe XML document to transform.
resultThe result tree after applying this stylesheet.
with_paramsOverride xsl:param elements using the given key/value map
on_errorHandler called to process errors and warnings (since 0.7.0).
Returns
True if the transformation was successful and the results placed in result.
False if there was an error, result is not modified.

◆ apply() [5/6]

xml::document& xslt::stylesheet::apply ( const xml::document doc,
xml::error_handler on_error = xml::throw_on_error 
)

Apply this stylesheet to the given XML document.

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

Each time you call this member function, the xml::document object that was returned from the last call becomes invalid. That is, of course, unless you copied it first.

Parameters
docThe XML document to transform.
on_errorHandler called to process errors and warnings (since 0.7.0).
Returns
A reference to the result tree.

◆ apply() [6/6]

xml::document& xslt::stylesheet::apply ( const xml::document doc,
const param_type with_params,
xml::error_handler on_error = xml::throw_on_error 
)

Apply this stylesheet to the given XML document.

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

Each time you call this member function, the xml::document object that was returned from the last call becomes invalid. That is, of course, unless you copied it first.

Parameters
docThe XML document to transform.
with_paramsOverride xsl:param elements using the given key/value map
on_errorHandler called to process errors and warnings (since 0.7.0).
Returns
A reference to the result tree.

◆ get_error_message()

const std::string& xslt::stylesheet::get_error_message ( ) const

If you used one of the xslt::stylesheet::apply member functions that return a bool, you can use this function to get the text message for the transformation error.

If you are using one of the apply member functions that throws exceptions, this function should not be used. The text message for the transformation error will be given to the xml::exception constructor.

Returns
The last error message.
Deprecated:
Use apply() variants that take xml::error_handler argument.

The documentation for this class was generated from the following file: