Hi,
I'm Mikhail Edoshin and this is my first post to the list. I'm trying to
write a few XSLT Extension element for various purposes and I'm not
quite sure if the behavior I'm observing is expected or I should submit
a bug request. Please help.
Here's the situation: I want to write an element to create a directory,
e.g.:
<path:make-directory target="{$target}" />
The $target variable is supposed to be defined by the XSLT processor.
The problem is that I cannot evaluate this expression or have it
evaluated with apply_templates() or something like. Here's what I've tried:
1. First, I can have it evaluated if I provide a child element and use
process_children():
<path:make-directory>
<target value="{$target}" />
</path:make-directory>
This construction works perfectly and for now I'm using it, but it's
less elegant, of course, than having it in an attribute.
2. I see that XPaths do not work with self_node or input_node, but I
don't quite understand why. I realize these elements are read-only, but
applying an XPath isn't going to change them, is it? Besides, it seems
that I can use context.context_node, which is same as input_node, but is
not read-only and thus can run any XPath or whatever. This is good to
have, although in my case it doesn't help, because I'd like to evaluate
a XSLT variable.
3. For the remaining tests I prepared the following example:
<path:make-directory>
<xsl:text>sample text</xsl:text>
<xsl:value-of select="$target" />
</path:make-directory>
- If I use process_children(), it evaluates as expected: 'sample text',
then the value of $target.
- If I try to apply_templates() to the extension itself, I only get
'sample text'.
- If I try to apply_templates() to each child element alone (using 'for
item in self_node') I seem to a) skip the <xsl:text> element and b) I
get no result. (From what I understand <xsl:text> is probably translated
directly to text content (text or tail); if so, it's OK, as I'm more
concerned about missing xsl:value-of.)
- If I try to create a new xsl:text and apply_templates() to it, I get
the text content of the element.
- If I try to create a new xsl:value-of and apply_templates() to it, I
get no result.
- If I try to create an arbitrary element (with sub-elements, etc.) and
apply_templates() to it, I only get element texts, if any; if there's no
text, I get nothing.
- Also, if I try to run process_children() without output_node, I get an
error: TypeError: invalid argument type <type 'NoneType'>
So, basically, what seems to be wrong is that:
- XPaths do not work with self_node and input_node.
- apply_templates() only adds text content, not elements or attributes.
- process_children() does not accept None for output_element (contrary
to the documentation).
The two latter sound like bugs to me, but I'm not sure about the XPath
limitation.
Kind regards,
Mikhail