LXML Extensions
dm.lxml_extensions
Module providing xpath extensions.
ext_entry_link_g(context, entries)
Provides a link to a glossary entry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context (containing the current node) |
required |
entries
|
list[_Element]
|
a list of entry elements |
required |
Returns:
Type | Description |
---|---|
str
|
a string containing an id of the glossary entry, or an empty string if no entry is found |
ext_entry_used_g(context, entries)
Checks if a glossary entry is used in the document.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context (containing the current node) |
required |
entries
|
list[_Element]
|
a list of entry elements |
required |
Returns:
Type | Description |
---|---|
bool
|
true, if the entry is used in the document, otherwise false |
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_lookup_g(context, refs)
Looks up a glossary term and returns a link to the entry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context (containing the current node) |
required |
refs
|
list[_Element]
|
a list of reference links (xhtml:a elements with data-type="xref" and data-xrefstyle="glossary") |
required |
Returns:
Type | Description |
---|---|
_Element
|
an element representing the link to the glossary entry, or the original reference if no entry is found |
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
|
second 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_term_g(context, terms)
Select the term to display for a glossary entry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
object
|
the xpath context (containing the current node) |
required |
terms
|
list[_Element]
|
a list of term elements |
required |
Returns:
Type | Description |
---|---|
str
|
the text of the first term element, with leading and trailing whitespace removed. |
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
- rstrip
- sentence-case
- simplify
- strip
- unique-id
- upper-case
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace
|
str
|
the namespace to register the extentions under. |
required |
register_glossary_extensions(namespace)
Registers the lxml extensions.
Registers the extensions
- used
- lookup
- link
- match
- term
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace
|
str
|
the namespace to register the extentions under. |
required |