我有下面的XML文本
S1/7/1以及下面的XSLT。
<xsl:template match="text()">
<xsl:analyze-string select="." regex="(\w+)/(\w+)/(\w+)">
<xsl:matching-substring>
<xsl:variable name="ChpnMatch">
<xsl:value-of select="substring(regex-group(1),1,1)"/>
</xsl:variable>
<xsl:variable name="regex1">
<xsl:choose>
<xsl:when test="$ChpnMatch = 'U'">
<xsl:text>HKWB2015EDSUPP2_CH_S4</xsl:text>
</xsl:when>
<xsl:when test="$ChpnMatch = 'B|D|E|L|R|F|H|K|Q|S'">
<xsl:text>HKWB2015EDSUPP2_CH_S3</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>HKWB2015EDSUPP2_CH_S1</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<a href="{concat('er:#',$regex1,'/P',regex-group(1),'-',regex-group(2),'-',regex-group(3))}">
<xsl:value-of select="."/>
</a>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>这里有一个案例<xsl:when test="$ChpnMatch = 'B|D|E|L|R|F|H|K|Q|S'">,这是结果应该是HKWB2015EDSUPP2_CH_S3的实际匹配,但捕获的结果是HKWB2015EDSUPP2_CH_S1 (即otherwise block)。你能让我知道我哪里出了问题以及如何解决这个问题吗?
这是工作演示
谢谢
发布于 2015-05-18 08:46:32
如果您想将一个字符串与其他字符串序列进行比较,那么您需要例如'S' = ('A', 'B', 'D', 'S'),所以我认为,您需要的不是xsl:when test="$ChpnMatch = 'B|D|E|L|R|F|H|K|Q|S'",而是xsl:when test="$ChpnMatch = ('B', 'D', 'E', 'L', 'R', 'F', 'H', 'K', 'Q', 'S')"。它检查$ChpnMatch是否等于序列('B', 'D', 'E', 'L', 'R', 'F', 'H', 'K', 'Q', 'S')中的至少一个字符串。
https://stackoverflow.com/questions/30297542
复制相似问题