Refactor an XPath expression: specify common subexpressions only once <p>I would like to summarize sub-expressions of the XPath expression specified as the <code>test</code> attribute of an <code>&lt;xsl:if&gt;</code> instruction, which could appear multiple times (and as part of different expressions) in my xslt stylesheet. For example:</p> <pre><code>&lt;xsl:if test=" preceding-sibling::node()[ (self::a and @attr1='a1') or (self::b and @attr2='b1') ] or following-sibling::node()[ (self::a and @attr1='a1') or (self::b and @attr2='b1') ] "&gt; ... &lt;/xsl:if&gt; </code></pre> <p>As you can see the sub-expression (<code>self::a and</code> ...) is repeated but the nodes upon which the predicate is applied may be different.</p>