The problem I'm trying to solve is to get all elements that contain only a unique text element but at the same time also being able to exclude node trees based on a element name passed as a parameter to the XSLT sheet.
The part to select all the nodes containing only a unique text element that's not empty was relatively easy:
$StartNode//element()/text()[normalize-space(.)]/parent::*
where $StartNode is a Xpath Expression to a specific Element in the XML document.
Now the part I had quite some some problems with, excluding an specific node tree from the results:
so I was hoping for something like:
$StartNode//element()/text()[normalize-space(.)]/parent::*[not(ancestor::**$element_to_be_excluded**)]
where $element_to_be_excluded is the element name to exclude.
But it's not possible to use a variable on that part of the expression...
So I came up with this solution
<xsl:variable name="ancestors_of_current_node" as="xs:string*">
<xsl:sequence select="$current_parent_node/ancestor::*/name()"/>
</xsl:variable>
<xsl:variable name="is_value_in_sequence" as="xs:boolean" select="functx:is-value-in-sequence($exclude_node_local_name, $ancestors_of_current_node)"/>
<xsl:if test="not($is_value_in_sequence)">
<xsl:call-template name="dataElementMap">
<xsl:with-param name="node_item" select="$current_parent_node"/>
</xsl:call-template>
</xsl:if>
where functx:is-value-in-sequence is:
<xsl:function name="functx:is-value-in-sequence" as="xs:boolean" xmlns:functx="http://www.functx.com">
<xsl:param name="value" as="xs:anyAtomicType?"/>
<xsl:param name="seq" as="xs:anyAtomicType*"/>
<xsl:sequence select="$value = $seq"/>
</xsl:function>
Now the question is, it's there a more elegant way to solve this problem?
Thanks in advance for any hint.
Regards Vlax