I’ve been battling this XSL (Saxon/Java) code for several hours now, and still can’t figure it. I narrowed the problem down to this snippet:
<xsl:function name="my:fff" >
<xsl:element name="p0">
<p1 aaa='AAA' />
</xsl:element>
</xsl:function>
<xsl:function name="my:ggg">
<xsl:variable name="v" select="my:fff()" />
<!-- Debug messages -->
<xsl:message>
$v '<xsl:sequence select="$v" />'
$v/* '<xsl:sequence select="$v/*" />'
$v/*/@aaa '<xsl:value-of select="$v/*/@aaa" />'
$v/p0 '<xsl:sequence select="$v/p0" />'
</xsl:message>
...
</xsl:function>
The output printed by the in my:ggg is as follows:
$v '<p0><p1 aaa="AAA"/></p0>'
$v/* '<p1 aaa="AAA"/>'
$v/*/@aaa 'AAA'
$v/p0 ''
The first three lines are fine. But the fourth line which outputs an empty string is weird. I mean, if $v is <p0><p1 aaa="AAA"/></po> (as indicated in the first line) then why is it that $v/p0 isn’t <p1 aaa="AAA"/> ?
What am I missing?
Your reasoning would be OK if the
my:fff()function was returning a document node — not an element (p0that itself doesn’t have ap0child).So, if you change the function to be the following:
And the complete transformation would be:
then applying this transformation on any XML document (not used), produces now the following debugging output:
which is probably what you want, with the exception of the
aaaattribute, which needs to be accessed as:$v/*/*/@aaa