Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.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
XSLT1.0以及如何在文本中找到一些关键字_Xslt - Fatal编程技术网

XSLT1.0以及如何在文本中找到一些关键字

XSLT1.0以及如何在文本中找到一些关键字,xslt,Xslt,我想使用XSLT1.0在文本中查找一些关键字 内容文本:海洋天气预报、警告、概要和冰况。数百个陆地和浮标观测站,以及海洋天气预报、警告、概要和冰况。数百个陆地和浮标站的观测遍布全球 关键词:“海洋天气,海洋天气,海洋天气” 分隔符: 下面的代码只有一个关键字有效…但我想找到多个关键字(“海洋天气,海洋天气,海洋天气”) ' 此转换: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transfor

我想使用XSLT1.0在文本中查找一些关键字

  • 内容文本:海洋天气预报、警告、概要和冰况。数百个陆地和浮标观测站,以及海洋天气预报、警告、概要和冰况。数百个陆地和浮标站的观测遍布全球

  • 关键词:“海洋天气,海洋天气,海洋天气”

  • 分隔符:
下面的代码只有一个关键字有效…但我想找到多个关键字(“海洋天气,海洋天气,海洋天气”)


'

此转换:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:param name="pKeyWords">
  <kw>Marine weather</kw>
  <kw>marine weather</kw>
  <kw>Marine Weather</kw>
 </xsl:param>

 <xsl:variable name="vKeyWords" select=
 "document('')/*/xsl:param[@name='pKeyWords']/*"/>

 <xsl:template match="/*">
  <t><xsl:apply-templates/></t>
 </xsl:template>

 <xsl:template match="text()" name="highlightKWs">
  <xsl:param name="pText" select="."/>

  <xsl:if test="not($vKeyWords[contains($pText,.)])">
   <xsl:value-of select="$pText"/>
  </xsl:if>

  <xsl:apply-templates select="$vKeyWords[contains($pText,.)]">
   <xsl:sort select="string-length(substring-before($pText,.))"
    data-type="number"/>
   <xsl:with-param name="pText" select="$pText"/>
  </xsl:apply-templates>
 </xsl:template>

 <xsl:template match="kw">
   <xsl:param name="pText"/>
   <xsl:if test="position()=1">
    <xsl:value-of select="substring-before($pText, .)"/>
    <span class="texthighlight">
     <xsl:value-of select="."/>
    </span>
    <xsl:call-template name="highlightKWs">
     <xsl:with-param name="pText" select="substring-after($pText, .)"/>
    </xsl:call-template>
   </xsl:if>
 </xsl:template>
</xsl:stylesheet>

海洋天气
海洋天气
海洋天气
应用于以下XML文档时:

<t>Marine weather forecasts,
warnings, synopsis, and ice conditions.
Hundreds of land and buoy station observations
across and marine weather forecasts, warnings,
synopsis, and ice conditions. Hundreds of land
and buoy station observations across.</t>
<t>
   <span class="texthighlight">Marine weather</span> forecasts,
warnings, synopsis, and ice conditions.
Hundreds of land and buoy station observations
across and <span class="texthighlight">marine weather</span> forecasts, warnings,
synopsis, and ice conditions. Hundreds of land
and buoy station observations across.</t>
海洋天气预报,
警告、概要和冰况。
数百个陆地和浮标观测站
海洋和海洋天气预报、警告,
概要,冰况。数以百计的土地
以及浮标观测站。
生成所需的正确结果:

<t>Marine weather forecasts,
warnings, synopsis, and ice conditions.
Hundreds of land and buoy station observations
across and marine weather forecasts, warnings,
synopsis, and ice conditions. Hundreds of land
and buoy station observations across.</t>
<t>
   <span class="texthighlight">Marine weather</span> forecasts,
warnings, synopsis, and ice conditions.
Hundreds of land and buoy station observations
across and <span class="texthighlight">marine weather</span> forecasts, warnings,
synopsis, and ice conditions. Hundreds of land
and buoy station observations across.</t>

海洋天气预报,
警告、概要和冰况。
数百个陆地和浮标观测站
海洋和海洋天气预报、警告,
概要,冰况。数以百计的土地
以及浮标观测站。