xslt - 在 XSL 标记化中访问匹配的模式

标签 xslt xpath

假设我有以下变量

<xsl:variable name="randomString" select="'COLUMN1 == 400 or COLUMN1 == 5 and COLUMN2 != 3'" />

是否有任何方便的方法来访问 tokenize() 函数中的匹配模式,例如用这个

<xsl:for-each select="tokenize($randomString, 'and|or')">
  <xsl:value-of select="concat('not(', current(), ')')" />
  <!-- How do I access the matched pattern? -->
</xsl:for-each>

或者我必须使用像我在这里找到的自定义模板吗 http://docbook.sourceforge.net/release/xsl/1.77.0/doc/lib/str.tokenize.keep.delimiters.html

最佳答案

不,没有办法检索匹配的分隔符。 “分隔符本身不会返回。” ( http://www.w3.org/TR/xpath-functions/#func-tokenize )

一种解决方法是,在外循环中使用 作为分隔符进行分词,然后在内循环中使用 作为分隔符进行分词。然后,根据您在循环中的位置,您将始终知道您正在处理哪些分隔符。

另一种方法是使用analyze-string()。参见 this answer .

关于xslt - 在 XSL 标记化中访问匹配的模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30516132/

相关文章:

xslt - FOP 警告 :line 1 of a paragraph overflows the available area by more than 50 points

xpath - normalize-space(.) 和 normalize-space(text()) 有什么区别?

xslt - 如何在 XSLT 中进行字符串操作?

python - 如何检查元素是否显示在网站上?

XPath 连接多个节点

具有多个 XSLT 样式表的 XML

XSLT 将 XSD 转换为带有 minOccurs 标签的另一个 XSD

excel - XSLT 输出 BOM 字符在 Excel 中可见

java - XSL 错误 - "... does not identify an external Java class"

selenium - 需要帮助查找标签旁边输入字段的 xpath