Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
String XSLT-如何删除某些单词并使用;或;_String_Xslt 2.0 - Fatal编程技术网

String XSLT-如何删除某些单词并使用;或;

String XSLT-如何删除某些单词并使用;或;,string,xslt-2.0,String,Xslt 2.0,我有一根这样的绳子 Advances in the field of radiotherapy 我希望从字符串中删除常用的停止词,如“in”、“the”、“of”等,并用“OR”连接结果字符串。所以,它看起来像 Advances OR field OR radiotherapy 停止字列表可能会增加,因此我不想使用replace()函数删除停止字。有没有一种方法可以保存所有停止词的列表,并使用该列表处理字符串 我可以使用XSLT 2.0解决方案。您可以使用停止词定义gobal参数,例如 &l

我有一根这样的绳子

Advances in the field of radiotherapy
我希望从字符串中删除常用的停止词,如“in”、“the”、“of”等,并用“OR”连接结果字符串。所以,它看起来像

Advances OR field OR radiotherapy
停止字列表可能会增加,因此我不想使用
replace()
函数删除停止字。有没有一种方法可以保存所有停止词的列表,并使用该列表处理字符串


我可以使用XSLT 2.0解决方案。

您可以使用停止词定义gobal参数,例如

<xsl:param name="stop-words" select="'in', 'the', 'of'"/>
输入为

<text>Advances in the field of radiotherapy</text>
放射治疗领域的进展 Saxon 9.5的输出是

<text>Advances OR field OR radiotherapy</text>
进展或领域或放射治疗
根据你的评论,我认为你只是想

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:mf="http://example.com/mf"
  exclude-result-prefixes="mf">

<xsl:param name="stop-words" select="'in', 'the', 'of'"/>

<xsl:param name="rep" select="' OR '"/>

<xsl:variable name="regex" 
  select="concat('(^|\W)(', string-join($stop-words, '|'), ')', '(\W(', string-join($stop-words, '|'), '))*($|\W)')"/>

<xsl:function name="mf:process">
  <xsl:param name="input"/>
  <xsl:sequence select="replace(replace($input, $regex, '$1$5'), '\s+', $rep)"/>
</xsl:function>

<xsl:template match="@* |  node()">
  <xsl:copy>
    <xsl:apply-templates select="@* , node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="text()[normalize-space()]" priority="5">
  <xsl:value-of select="mf:process(.)"/>
</xsl:template>

</xsl:stylesheet>

哪种转变

<root>
<text>Advances in the field of radiotherapy</text>
<text>Advances made in the field of radiotherapy</text>
</root>

放射治疗领域的进展
放射治疗领域的进展
进入


放射治疗领域的进展
进步,进步,进步,进步,进步

甚至可以进一步简化模式,我将把它留作练习。

我将字符串放在变量中,因此我想我可以使用字符串作为参数调用包含analyze字符串的模板,比如使用名称“text”,并替换所有的字符串。使用$text?是,使用字符串类型的参数(例如
)编写命名模板或函数,然后在模板或函数内部使用
而不是
。但是,不应更改
,因为它位于分析字符串中,并输出与模式不匹配的任何内容的值。抱歉,问题似乎不是很清楚。我不想用“或”来代替停止词。我想删除停止词,然后在有空白的地方插入“或”。当前解决方案将停止字替换为“或”。它不适用于放射治疗领域的-
进步
,它应该转变为-
进步或进步或进步、领域或放射治疗
,而不是
进步或领域或放射治疗
。你能修改一下解决方案吗?
<root>
<text>Advances in the field of radiotherapy</text>
<text>Advances made in the field of radiotherapy</text>
</root>
<root>
<text>Advances OR field OR radiotherapy</text>
<text>Advances OR made OR field OR radiotherapy</text>
</root>