Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml XSLT组合多功能_Xml_Xslt - Fatal编程技术网

Xml XSLT组合多功能

Xml XSLT组合多功能,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'))"/> </

将多个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>


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

在XSLT 3和XPath 3.1中,您可以使用箭头操作符
=>
()来编写

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

您可以在以下位置比较两个版本:

哪一个

<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>

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

非常好的解决方案。从哪个Saxon版本支持它?对于Xsltransform的标准版本(Saxon 9.5.x),我得到了错误500:XSLT 3和XPath 3.1仅在Saxon 9.8的所有版本中受支持。我认为早期版本的Saxon EE和PE支持它,它们通常分别实现XSLT的工作草案XPath 3。建议9.7 EE/PE中支持箭头运算符。基于此,它看起来不是9.6中实现的特性。同时,我发现了这些信息。现在我要离开话题了。:/目前,我正在尝试将Saxon 9.8添加到本地Xsltransform副本中。我找到了你的fork@Github,但是只有一个回复“更新到9.8”提交,但是在你链接的站点上是一个9.8版本。您是否知道如何将Xsltransform更新到9.8版本?至于说,它是我对xsltransform.NET所基于的Java/Scala play framework应用程序所做的ASP.NET MVC 5“克隆”,因此它有一个完全不同的后端,使用.NET版本的Saxon 9.8 HE作为XSLT 3处理器,并使用Microsoft实体框架进行数据库访问。因此,恐怕您不能对xsltransform的本地副本进行更新。谢谢,我希望xsltransform的原始作者在将来继续开发。在此之前,我将在需要时使用您的版本。请参阅@MartinHonnen的答案。如果不支持XPath3.1,可以将中间结果绑定到变量。
<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>