You can use replace(., 'foo|bar', 'whatever')
to have both foo
and/or bar
substrings replaced with whatever
. The second argument of replace
is a regular expression and therefore |
allows alternatives.
Can I use the OR operator in <xsl:value-of select>?
-
13-10-2022 - |
Question
I have been using the following piece of code to replace the regular expression '\s*AND\s*NOT\s*scope:\("TEXT"\)'
with a specific string only if the match does not occurr (non-matching-substring
):
<xsl:template name="strip-scopes">
<xsl:param name="q" />
<xsl:analyze-string select="$q" regex='\s*AND\s*NOT\s*scope:\("TEXT"\)'>
<xsl:matching-substring></xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="replace(replace(.,'AND \(scope:.*?\)',''), 'AND facet_.*?:\(.*?\)', '')"/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
It works fine, but I now need to include another condition in the <xsl:non-matching-string
>. Is it possible to include an OR condition inside the element, so that both 'AND facet_.*?:\(.*?\)'
and 'AND NOT facet_.*?:\(.*?\)'
replacements can be allowed?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow