I have a list of conditions, and I want to check if the immediate sibling of an element matches any of those conditions.
If these conditions are simple tag names, this is easy enough.
<xsl:param name="tag-list" select="tokenize('img figure table', '\s+')"/>
<xsl:template match="* | text()">
<xsl:variable name="next-name" select="name(following-sibling::*[1])" />
<xsl:if test="$next-name = $tag-list">
<!-- DoSomething -->
</xsl:if>
</xsl:template>
This template will match any element or text node, and will DoSomething if the immediate following sibling of that node is either <img>, <figure> or <table>
.
However, I want to check for more complex conditions. How can I only DoSomething for when the template matches against elements with a sibling with a specific attribute, child or text value? I would prefer to do this with a single <xsl:if>
, as this list of sibling conditions could get pretty long.
<xsl:param name="tag-list" select="tokenize('img[@src] figure[text()] table[tbody]', '\s+')"/>
<xsl:template match="* | text()">
<xsl:if test="???">
<!-- DoSomething -->
</xsl:if>
</xsl:template>