PyPop.xslt#
Python XSLT extensions for handling things outside the scope of XSLT 1.0.
Attributes#
Function namespace for custom PyPop XSLT extension functions. |
Functions#
|
Count zeroes. |
|
Calculate space taken for exponent. |
|
Format number to fixed width. |
Package Contents#
- ns#
Function namespace for custom PyPop XSLT extension functions.
This namespace allows registering Python functions that can be called directly from XSLT stylesheets.
- prefix#
The namespace prefix used in XSLT stylesheets. Here it is set to
"es"
, so extension functions are invoked ases:format_number_fixed_width(...)
. See example informat_number_fixed_width()
- Type:
- num_zeros(decimal)#
Count zeroes.
- exponent_len(num)#
Calculate space taken for exponent.
Example
>>> exponent_len(1e-03) 2 >>> exponent_len(1e-10) 3
- format_number_fixed_width(_context, *args)#
Format number to fixed width.
Example
>>> ns["format_number_fixed_width"] = format_number_fixed_width >>> root = etree.XML("<a><b>0.0000043</b></a>") >>> doc = etree.ElementTree(root) >>> xslt = etree.XSLT(etree.XML(''' ... <stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:es="http://pypop.org/lxml/functions"> ... <output method="text" encoding="ASCII"/> ... <template match="/"> ... <text>Yep [</text> ... <value-of select="es:format_number_fixed_width(string(/a/b), 5)"/> ... <text>]</text> ... </template> ... </stylesheet> ... ''')) >>> >>> print(xslt(doc)) Yep [4.3e-6]
Note
arguments from XSLT file:
num
andplaces
are encoded in*args
.- Parameters:
_context (obj) – not used
- Returns:
formatted number to fixed width
- Return type: