xml - XSLT 结合多种功能

标签 xml xslt

将多个 XSLT 函数组合到一行中是个好主意吗?

<xsl:template match="title" >
        <xsl:copy>
            <xsl:value-of select="normalize-space(replace(replace(replace(.,'OK',''),'^.\d+Something',''),'((Special10)\s+)[0-9]+\s+(.*)','$1$3'))"/>
        </xsl:copy>
</xsl:template>

还有比这更可读的解决方案吗?

最佳答案

在带有 XPath 3.1 的 XSLT 3 中,您可以使用箭头运算符 => ( https://www.w3.org/TR/xpath-31/#id-arrow-operator ) 来编写例如

normalize-space(replace(replace(replace(.,'OK',''),'^.\d+Something',''),'((Special10)\s+)[0-9]+\s+(.*)','$1$3'))

作为

. => replace('OK', '') => replace('^.\d+Something','') => replace('((Special10)\s+)[0-9]+\s+(.*)','$1$3') => normalize-space()

您可以在 http://xsltfiddle.liberty-development.net/pPgCcoq 上比较两个版本,

这确实

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="3.0">

  <xsl:mode on-no-match="shallow-copy"/>

    <xsl:template match="title" >
            <xsl:copy>
                <xsl:value-of select="normalize-space(replace(replace(replace(.,'OK',''),'^.\d+Something',''),'((Special10)\s+)[0-9]+\s+(.*)','$1$3'))"/>
            </xsl:copy>
    </xsl:template>

    <xsl:template match="title2" expand-text="yes">
        <xsl:copy>{. => replace('OK', '') => replace('^.\d+Something','') => replace('((Special10)\s+)[0-9]+\s+(.*)','$1$3') => normalize-space()}</xsl:copy>
    </xsl:template>

</xsl:stylesheet>

关于xml - XSLT 结合多种功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48345668/

相关文章:

java - 尝试在空对象引用上调用虚拟方法 'android.webkit.WebSettings android.webkit.WebView.getSettings()'

xml - 使用 Hadoop 处理 xml 文件

parsing - XSLT-预定义命名空间

XSLT/XPath : No upper-case function in MSXML 4. 0?

xml - xslt 1.0 - 如何使用相同级别的元素进行嵌套分组

java - 为什么我的 CardView 不会出现在我的 fragment 中?

xml - 如何为 mp4box 创建 CENC 加密的 xml 文件?

javascript - 如何在wcf服务中获取Xml作为字符串并使用javascript发送?

XSLT xsl :sequence. 它有什么用..?

xml - 如何使用 count() 函数是 XSL - 尝试计算报告中 "A"的数量