You can nest a second xsl:analyze-string
into the xsl:non-matching-substring
if you want but of course the content of any xsl:analyze-string
has to follow the rules
The content of the xsl:analyze-string instruction must take one of the following forms:
A single xsl:matching-substring instruction, followed by zero or more xsl:fallback instructions A single xsl:non-matching-substring instruction, followed by zero or more xsl:fallback instructions A single xsl:matching-substring instruction, followed by a single xsl:non-matching-substring instruction, followed by zero or more
xsl:fallback instructions
[ERR XTSE1130] It is a static error if the xsl:analyze-string instruction contains neither an xsl:matching-substring nor an xsl:non-matching-substring element.
So don't put an xsl:choose
inside of it directly, rather xsl:matching-substring
and/or xsl:non-matching-substring
, which can then take any sequence constructor if needed, which allows xsl:choose
of course.
Here is a complete example that is well-formed XML and syntactically correct XSLT:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template name="facets">
<xsl:param name="q" />
<xsl:analyze-string select="$q" regex='AND facet_(.*?):\(("?.*?"?)\)'>
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="regex-group(1) = 'example1'">
<facet name="domain"><xsl:value-of select="regex-group(2)" /></facet>
</xsl:when>
<xsl:when test="regex-group(1) = 'example2'">
<facet name="content_type_norm"><xsl:value-of select="regex-group(2)" /></facet>
</xsl:when>
<xsl:when test="regex-group(1) = 'example2'">
<facet name="sentiment"><xsl:value-of select="regex-group(2)" /></facet>
</xsl:when>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="$q" regex='AND NOT facet_(.*?):\(("?.*?"?)\)'>
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="regex-group(1) = 'example1'">
<facet name="domain"><xsl:value-of select="regex-group(2)" /></facet>
</xsl:when>
<xsl:when test="regex-group(1) = 'example2'">
<facet name="content_type_norm"><xsl:value-of select="regex-group(2)" /></facet>
</xsl:when>
<xsl:when test="regex-group(1) = 'example2'">
<facet name="sentiment"><xsl:value-of select="regex-group(2)" /></facet>
</xsl:when>
</xsl:choose>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
Try to use an XML editor or editor plugin, it helps getting the proper nesting, and tag completion should avoid errors with typos like </xsl:matching-sustring>
.