LXML Extensions
dm.lxml_extensions
Module providing xpath extensions.
ext_id(context, text)
Generates a textual id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context |
required |
text
|
str | list[str]
|
a text string |
required |
Returns:
Type | Description |
---|---|
str
|
the text, with whitespaces converted to '', and prefixed by '' |
ext_lowercase(context, text)
Converts a text to lowercase.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context (containing the current node) |
required |
text
|
str | list[str]
|
a text string |
required |
Returns:
Type | Description |
---|---|
str
|
the text converted to lowercase |
ext_lstrip(context, text)
Removes leading whitespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context |
required |
text
|
str | list[str]
|
a text string |
required |
Returns:
Type | Description |
---|---|
str
|
the text without leading whitespace |
ext_match_g(context, text, used_text)
Compares two texts case-insensitive.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context |
required |
text
|
str
|
first string |
required |
used_text
|
str
|
seconde string |
required |
Returns:
Type | Description |
---|---|
bool
|
true, if the strings are equal when compared case-insensitive, otherwise false |
ext_rstrip(context, text)
Removes trailing whitespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context |
required |
text
|
str | list[str]
|
a text string |
required |
Returns:
Type | Description |
---|---|
str
|
the text without trailing whitespace |
ext_sentencecase(context, text)
Capitalize a text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context (containing the current node) |
required |
text
|
str | list[str]
|
a text string |
required |
Returns:
Type | Description |
---|---|
str
|
the text with the first character uppercase, all other lowercase |
ext_simplify(context, text)
Simplifies whitespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context (containing the current node) |
required |
text
|
str | list[str]
|
a text string |
required |
Returns:
Type | Description |
---|---|
str
|
the text with multiple consecutive whitespace converted to a single space |
ext_strip(context, text)
Removes leading and trailing whitespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context |
required |
text
|
str | list[str]
|
a text string |
required |
Returns:
Type | Description |
---|---|
str
|
the text without leading and trailing whitespace |
ext_unique_id(context)
Calculates a unique id for the current node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context (containing the current node) |
required |
Returns:
Type | Description |
---|---|
str
|
an ID for the current node, unique within the XML document |
ext_uppercase(context, text)
Converts a text to uppercase.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context (containing the current node) |
required |
text
|
str | list[str]
|
a text string |
required |
Returns:
Type | Description |
---|---|
str
|
the text converted to uppercase |
register_dossier_extensions(namespace)
Registers the lxml extensions.
Registers the extensions
- id
- lower-case
- lstrip
- match-g
- rstrip
- sentence-case
- simplify
- strip
- unique-id
- upper-case
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace
|
str
|
the namespace to register the extentions under. |
required |