saxonche is the official Saxonica Python wheel package for the SaxonC-HE processor, an XML document processor. It provides APIs to run XSLT 3.0 transformations, XQuery 3.1 queries, XPath 3.1, and XML Schema validation. This library allows Python developers to leverage Saxon's robust and standards-compliant XML processing capabilities, including experimental support for draft 4.0 specifications.
pip install saxoncheVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to perform an XSLT 3.0 transformation using `saxonche`. It initializes a `PySaxonProcessor`, parses an XML document, compiles an XSLT stylesheet, and then applies the transformation to produce an output string. It uses `license=False` to indicate the open-source Home Edition.
Ensure you install the correct package (`saxonche`, `saxoncpe`, or `saxoncee`) and manage licenses appropriately for commercial editions.
Set the `SAXONC_HOME` environment variable or programmatically set the `licenseFileLocation` property before performing any operations with a licensed processor.
Refer to the SaxonC Python API documentation for details on data type conversions and use appropriate `PySaxonProcessor` methods (like `make_string_value`, `make_boolean_value`, etc.) when passing values between Python and Saxon's XDM.
Configure Pylint to allow importing from the C extension by adding `--extension-pkg-allow-list=saxonche` to your Pylint command or configuration file.
Update your code to call `PyXdmFunctionItem.get_system_function()` as a static method and remove the `PySaxonProcessor` argument from calls to `PyXdmFunctionItem.call()`.
On Windows, catch `RuntimeError` for Saxon-specific errors. For cross-platform compatibility, consider catching a broader `Exception` and inspecting the `proc.error_message()` for detailed error information.
Run `pip install saxonche` to install the library.
Reinstall `saxonche` using `pip install --no-cache-dir saxonche` to ensure a fresh download and installation. Verify Python version and system architecture compatibility.
Use the correct method name according to the `saxonche` API, such as `transform_to_string`, `transform_to_file`, or `transform_to_xdm_value`.
```python
import saxonche
with saxonche.PySaxonProcessor(license=False) as saxon:
xsltproc = saxon.new_xslt30_processor()
xml_doc = saxon.parse_xml(xml_text='<data/>')
xslt_doc = saxon.parse_xml(xml_text='<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><output/></xsl:template></xsl:stylesheet>')
result = xsltproc.transform_to_string(source=xml_doc, stylesheet=xslt_doc)
```Carefully review and correct the XSLT stylesheet for syntax errors, missing root elements (`xsl:stylesheet` or `xsl:transform`), or structural issues. Refer to XSLT specifications for guidance.