Skip to main content

A python package for the SaxonC-HE 12.0, an XSLT 3.0, XQuery 3.1, XPath 3.1 and Schema Validator processor by Saxonica.

Project description

Welcome to SaxonC HE!

This is the official Saxonica Python wheel package for Saxon, an XML document processor. SaxonC includes a range of tools for XML transformations, XML queries, and schema validations.

The SaxonC release comes in separate wheels for the three product editions, namely: saxonche (HE: open-source), saxoncpe (PE: professional edition) and saxoncee (EE: enterprise edition). SaxonC-PE and SaxonC-EE are commercial products that require an activation license.

When to choose SaxonC

The main reason for using SaxonC in preference to other XML tools available for Python is that it supports all the latest W3C standards: XSLT 3.0, XPath 3.1, XQuery 3.1, and XSD 1.1. It even includes experimental support for the draft 4.0 specifications currently under development.

Installation

pip install saxonche

Usage

from saxonche import *

Import specific modules

from saxonche import PySaxonProcessor

Now, let's check what processors are available see our docuemntation: Saxonica's site. In the API section, you will find more information about what each processor does.

Next, we will use PySaxonProcessor to check the Saxon version.

from saxonche import PySaxonProcessor

with PySaxonProcessor(license=False) as proc:
	print(proc.version)

It will print the version like below if your installation is successful.

SaxonC-he 12.0 from Saxonica

Please note that license=False requests the open-source version of Saxon, whereas license=True requests the commercial product. A license file is required for this to work. You can use the SAXONC_HOME environment variable to locate the license file or install the file next to the SaxonC library.

Example #1

Let's parse a toy XML.

from saxonche import PySaxonProcessor

with PySaxonProcessor(license=False) as proc:
	xml = """\
		<out>
			<person att1='value1' att2='value2'>text1</person>
			<person>text2</person>
			<person>text3</person>
		</out>
		"""
	node = proc.parse_xml(xml_text=xml)
	print("node.node_kind="+ node.node_kind_str)
	print("node.size="+ str(node.size))
	outNode = node.children
	print("len of children="+str(len(node.children)))
	print('element name='+outNode[0].name)
	children = outNode[0].children
	print(*children, sep= ', ')
	attrs = children[1].attributes
	if  len(attrs) == 2:
		print(attrs[1].string_value)

In the output, we will get this.

node.node_kind=document
node.size=1
len of children=1
element name=out
        , <person att1="value1" att2="value2">text1</person>, 
        , <person>text2</person>, 
        , <person>text3</person>, 
value2

As we can see, we can explore the XML node structure, attributes, and many other things if you check more on the APIs.

Example #2

Let's use the XML path processor.

from saxonche import PySaxonProcessor

with PySaxonProcessor(license=False) as proc:
	xml = """\
		<out>
			<person>text1</person>
			<person>text2</person>
			<person>text3</person>
		</out>"""

	xp = proc.new_xpath_processor()
	node = proc.parse_xml(xml_text=xml)
	xp.set_context(xdm_item=node)
	
	item = xp.evaluate_single('//person[1]')
	if  isinstance(item,PyXdmNode):
		print(item.string_value)
	# pay attention, Saxon's xdm data type
	value = proc.make_double_value(3.5)
	print(value.primitive_type_name)

The output shows here.

text1
Q{http://www.w3.org/2001/XMLSchema}double

Saxon shows the result given the path.

Example #3

The XSLT processor, #1

from saxonche import PySaxonProcessor

with PySaxonProcessor(license=False) as proc:
	xsltproc = proc.new_xslt30_processor()
	
	document = proc.parse_xml(xml_text="<out><person>text1</person><person>text2</person><person>text3</person></out>")

	xsltproc.set_source(xdm_node=document)
	exeuctable = xsltproc.compile_stylesheet(stylesheet_text="<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='2.0'> <xsl:param name='values' select='(2,3,4)' /><xsl:output method='xml' indent='yes' /><xsl:template match='*'><output><xsl:value-of select='//person[1]'/><xsl:for-each select='$values' ><out><xsl:value-of select='. * 3'/></out></xsl:for-each></output></xsl:template></xsl:stylesheet>")

	output2 = exeuctable.transform_to_string()
	print(output2)

Here is the output that shows the result of transformation.

<?xml version="1.0" encoding="UTF-8"?>
<output>text1<out>6</out>
   <out>9</out>
   <out>12</out>
</output>

Example #4

Watch out for the not-pythonic way!

from saxonche import PySaxonProcessor

with PySaxonProcessor(license=False) as proc:
	xsltproc = proc.new_xslt30_processor()

	xml = '<a><b>Text</b></a>'
	xslt = '''\
		<xsl:stylesheet version="1.0"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
		<xsl:param name="a" />
		<xsl:output method='xml' indent='yes' />
		<xsl:template match="/">
		<foo><xsl:value-of select="$a" /></foo>
		</xsl:template>
		</xsl:stylesheet>'''

	document = proc.parse_xml(xml_text=xml)

	#please note the not Python way in the next two lines.
	xdm_a = proc.make_string_value('a was given in the parameter')
	xsltproc.set_parameter('a', xdm_a)

	xsltproc.set_source(xdm_node=document)
	executable = xsltproc.compile_stylesheet(stylesheet_text=xslt)
	output2 = xsltproc.transform_to_string()
	print(output2)

Here we use an XSLT/stylesheet parameter. Note that the Python string is not the same string that Saxon uses, and the same goes for other types. We need to convert it by calling make_string_value. This is because there isn't an exact match between the type system used by XSLT (called XDM) and Python's data types: for some types like strings and booleans there is a very close correspondence, but for numbers, dates, URIs etc it's less exact.

Please check out Saxonica's documentation for xquery, schema validation, and others.

Why the with keyword?

Using with assures that the underlying processes are cleared out when the block finishes.

Source code & Development

Acknowledgement

To create this wheel project we had help from the Saxonpy wheel package, which is a third-party project created by github repo.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

saxonche-12.0.0-pp39-pypy39_pp73-win_amd64.whl (16.8 MB view details)

Uploaded PyPyWindows x86-64

saxonche-12.0.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.2 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

saxonche-12.0.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (16.9 MB view details)

Uploaded PyPymacOS 10.9+ x86-64

saxonche-12.0.0-pp38-pypy38_pp73-win_amd64.whl (16.8 MB view details)

Uploaded PyPyWindows x86-64

saxonche-12.0.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.3 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

saxonche-12.0.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (16.9 MB view details)

Uploaded PyPymacOS 10.9+ x86-64

saxonche-12.0.0-cp311-cp311-win_amd64.whl (16.6 MB view details)

Uploaded CPython 3.11Windows x86-64

saxonche-12.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

saxonche-12.0.0-cp311-cp311-macosx_11_0_arm64.whl (16.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

saxonche-12.0.0-cp311-cp311-macosx_10_9_x86_64.whl (16.7 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

saxonche-12.0.0-cp310-cp310-win_amd64.whl (16.6 MB view details)

Uploaded CPython 3.10Windows x86-64

saxonche-12.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

saxonche-12.0.0-cp310-cp310-macosx_11_0_arm64.whl (16.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

saxonche-12.0.0-cp310-cp310-macosx_10_9_x86_64.whl (16.7 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

saxonche-12.0.0-cp39-cp39-win_amd64.whl (16.6 MB view details)

Uploaded CPython 3.9Windows x86-64

saxonche-12.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

saxonche-12.0.0-cp39-cp39-macosx_11_0_arm64.whl (16.7 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

saxonche-12.0.0-cp39-cp39-macosx_10_9_x86_64.whl (16.7 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

saxonche-12.0.0-cp38-cp38-win_amd64.whl (16.6 MB view details)

Uploaded CPython 3.8Windows x86-64

saxonche-12.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.0 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

saxonche-12.0.0-cp38-cp38-macosx_11_0_arm64.whl (16.7 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

saxonche-12.0.0-cp38-cp38-macosx_10_9_x86_64.whl (16.7 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

File details

Details for the file saxonche-12.0.0-pp39-pypy39_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-pp39-pypy39_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 cc822f311a9878128f5df53297dc2cfd3f6f1964e3c36d24b9ed05c22323281d
MD5 ba3928dd7f180cfab23e0240e0b4ab25
BLAKE2b-256 8d7e4bcbabfd5d7d545682f62307c942a4440dd713bc693d55f2e5c18c9fc474

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5a8729b3c576359099754152f694ccbfe7ab218e9c706519ea236af9b0ebcd31
MD5 5efbfd9bdceebe7b1a21d5eb9d7400a0
BLAKE2b-256 d982f8775daf4eb7867e65ef13dbaca7ed059166a33a95a04ea75bebdda550f3

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5d3cc3f74f3d635fce349bc4d39920282d228738401be125624ff2a9933ca7ac
MD5 d6c01017843329cccba57363e1f952bd
BLAKE2b-256 2a01fa988a7bef6ea3116fafda7ba0d3fff4cfd877acef47d63e6362b0adbe6d

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-pp38-pypy38_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-pp38-pypy38_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 489f416123a9190f90c34185cbf77ec0865a3c01438f56aaffa9d9ea1129259c
MD5 4faebb8b3c75b57958c01d88caca9ead
BLAKE2b-256 9e8089feed6f3a0c1d7ef678507819c628855c80b3a4f6ca1bf3acdd001cb641

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 73b617aaadf77d4bd38ec366fe137607f5d298bb587bf7a72f3595f8caeef6de
MD5 87da27d516baa89900a0d240e5d5f0c1
BLAKE2b-256 7f984e3b9e0dc054d6e86cd2e99a45ff4851d07c8a4726316430afb80472c568

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a59f02b4ef80e6238f93ba733afa25babd1149896c70ed27a351cf33341d538f
MD5 8b971fce3a0c32613fa283c851f6ef58
BLAKE2b-256 e14d30c11185a3db1fb06b7369e130d8dd36d1ac1be8ce53d20daa60d5786b59

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: saxonche-12.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 16.6 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.10

File hashes

Hashes for saxonche-12.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2654f3a5a26321472b107323008b080c895129f80a9d66d58299c58b5535fcf9
MD5 4a9f927477e7e9821c1c4b7a87f7daf8
BLAKE2b-256 ce59f6fdf1051fd51a900dc8d1d17333a2cfd17be456be2212b87ba3179d41ed

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 89cce1cc2a62d74f6c759bc319b337f37587b46fd253788b36df65b226e21e5c
MD5 78eeb3c84c5ffe7e143fdbab0886bbcd
BLAKE2b-256 c39b512f388476ff05637a867a79ec4b6eeb6702a9f2ca83a5a80c789b1eac7f

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dd3f315581569c22050cf4d1bd3f36a435305f2189c6a979d88400ea5f058b21
MD5 85f86e6c38db3683ba58184a40962be6
BLAKE2b-256 b3a39f8c45b1afb552559dbedda40b9d6a94abb6fbf2b81ef06e959d1fdd23f8

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 aa69588377e73bd16190ead01c0cdc7244f55778fe008818dcb7d5c9ef0d9815
MD5 ef8c335137c8ebc19f37a59234af5b55
BLAKE2b-256 3187071cee7de68d9a97a66a7cf66479067c794e14d35ebf3f309998620bd5b7

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: saxonche-12.0.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 16.6 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.10

File hashes

Hashes for saxonche-12.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4081a81029bb9a32beaa244c068f06c2ac00aab81ebd3e9def9418ff5f9f803f
MD5 05d711a59e1a0007afc3a4b9f872e067
BLAKE2b-256 577a01f8751565a8759ca32135d2be82e0c21e0fc16a0a3601c3e9f39fce65b3

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4af9ac360b8a51308972a460860c76e97c010effc9db6abac0430d37fe806b85
MD5 de2c359c7183a25944641b8235acc281
BLAKE2b-256 f57e2f382e7e4f2baff0f8fef7e9fdc6a428aa99dfe94a28dd2a78fef19b09e6

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e55e07127b29a6d32eaa7d21be0116ada0f04a6a01174b23ec2cbee1185f9fbd
MD5 c9a7acbca60b627a91e5b08d79471423
BLAKE2b-256 264d9104d18f1259a39bb0aa4b4c30691a46ddd9da56dae469c1babe6b196323

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1624378b009ab42f2457fd85cb32f9a7525754934887606ef694d88794da1a7b
MD5 89ab8cbfd2f80f82ce7e0aa5f39dab4a
BLAKE2b-256 6a6d5fedac947e4c473e024838e2f360059c351eff1f26bd37c04d3998c4af6d

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: saxonche-12.0.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 16.6 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.10

File hashes

Hashes for saxonche-12.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e85b4f78c077e5cebf81386fc1868ce9659bc0baa7fcd3868f44c1fd3186f385
MD5 1b883dda35d3fb4a24768c2ddb35159d
BLAKE2b-256 d23f4992b98dfc6c107b1e9fcff34353c52128505a4ad32a960624495d57c231

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0bc77b842798035ef6999ecad96f0092f7eba143fca753a39ad6a8133273085
MD5 1e62474e47d4266abe2112c4e7cd590b
BLAKE2b-256 d93deb6b46aed62f1ab864fe27f591d8e0c1c8d509c70b40f1320ada1f8e838d

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3f74d99e84024dae84b6cd1c79b6ae1ac0263a72af0eb4512e2865f066755d21
MD5 bb25a34505ca0001a2bbdafd53b2da3b
BLAKE2b-256 31c17b8eec6d3e6ffa670b980060d471878d796db62eb16bd995d921717ac6db

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2a63495070672c09b3563900dc04d89ee78670c51d71f3a1e2dc9e5b9ebdc669
MD5 301ad94433e4dcc7d22d3d59fa153983
BLAKE2b-256 36f5191e9c9b34c67f39db4abbaac21f392f8db17fcfc8c2a567962ec4a5f6fc

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: saxonche-12.0.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 16.6 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.10

File hashes

Hashes for saxonche-12.0.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 210ddb1988405e4ec5b08de6343153a1b499e3d9f4888f7389dbdc50e6a6e8bc
MD5 b19666ca5353fd5148bd1ff975de4b82
BLAKE2b-256 c71a35cc65ce1a2f51e96fce9b5165b2a9dd4f399555fab860c2bf2e657b2117

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3dde83642e35baf5d5a99076af594ab346cbb69ce51a217ace74200498fee153
MD5 c4c08cfef362b9fac0d729b977551830
BLAKE2b-256 ecf571a0a8afe4093bed7c40404658e765e009fa23074030fbe4357c55487d89

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 55dd81fe221447113475509ea7f6eb938828a950c330e3efb383ab49192c1536
MD5 e3d66d331a266b2651427eeeb5ad39c5
BLAKE2b-256 08f02aa124b5e3b434a05236ebec1593e5e1fed018b81d440be0d19de3878aa6

See more details on using hashes here.

File details

Details for the file saxonche-12.0.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for saxonche-12.0.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4b2515d7ee48fb74eb9096de04bed2a9145abbffb369be0512ceaedd66757e92
MD5 a6ed4c0338de40f6c79c97793872bc8a
BLAKE2b-256 c157e0410a98c61948fe4bad8f79ef33ac6dbe14f1d0eb37fff40b8782324a79

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page