English 中文(简体)
XSLT在另一个词中找到了字句。
原标题:XSLT find word near another word
  • 时间:2010-05-31 15:09:48
  •  标签:
  • xslt
  • text

如何在案文节中找到另一字之前和之后的字句?

问题回答

I. In XSLT 2.x / XPath 2.x one can use the functions tokenize(-of(

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

 <xsl:param name="pWord" select=" three "/>

 <xsl:template match="text()">
   <xsl:sequence select=
    "tokenize(.,  ,s* )
        [index-of(tokenize(current(),  ,s* ), $pWord) -1]"/>

   <xsl:sequence select=
    "tokenize(.,  ,s* )
        [index-of(tokenize(current(),  ,s* ), $pWord) +1]"/>
 </xsl:template>
</xsl:stylesheet>

www.un.org/Depts/DGACM/index_spanish.htm 在以下XML文件适用这一转变:

<t>One, two, three, four</t>

<t, 正确结果::

two four

II.XSLT 1.0 Solutions

可在XSLT1.0中利用<代码>Spstrlit-to-Words模板解决同一任务:SL

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:ext="http://exslt.org/common"
>
   <xsl:import href="strSplit-to-Words.xsl"/>

   <xsl:output method="text"/>

   <xsl:param name="pWord" select=" three "/>

    <xsl:template match="/">
      <xsl:variable name="vrtfwordNodes">
        <xsl:call-template name="str-split-to-words">
          <xsl:with-param name="pStr" select="/"/>
          <xsl:with-param name="pDelimiters" 
                          select=" , &#9;&#10;&#13; "/>
        </xsl:call-template>
      </xsl:variable>

      <xsl:variable name="vwordNodes"
         select="ext:node-set($vrtfwordNodes)/*"/>

      <xsl:variable name="vserchWordPos" select=
      "count($vwordNodes
                 [. = $pWord]/preceding-sibling::*
             ) +1"/>

      <xsl:value-of select=
       "concat($vwordNodes[$vserchWordPos -1],
                  ,
               $vwordNodes[$vserchWordPos +1]
               )
       "/>
    </xsl:template>
</xsl:stylesheet>

www.un.org/Depts/DGACM/index_spanish.htm 当这一转变适用于同一XML文件时:

<t>One, two, three, four</t>

<t, 正确结果::

two four




相关问题
Which non-bold UTF-8 iPhone SDK font can I use here?

Problem: I create a UILabel with this font: label.font = [UIFont systemFontOfSize:15.0f]; Now this system font is bold, but I want to display pretty small text, and the text may also contain very ...

Limiting file upload type

Simple question. Is there a way to only allow txt files upon uploading? I ve looked around and all I find is text/php, which allows PHP. $uploaded_type=="text/php

Extract everything from PDF [closed]

Looking for solution to extract content from a PDF file (using console tool or a library). It will be used on server to produce on-line e-books from uploaded PDF files. Need to extract following ...

Flash & external form fields

Does anybody know if this is possible? I am trying to create a flash movie that will show / preview what I am typing into a field in a normal HTML form. The call to update the flash movie would most ...

Avoiding escape sequence processing in ActionScript?

I need to mimic C# functionality of the @ symbol when it precedes a string. @"C:AFilePath" for example What is the best way to do this? Also there are some sites that will escape larger ...

iPhone: Draw rotated text?

I want to draw some text in a view, rotated 90°. I m pretty new to iPhone development, and poking around the web reveals a number of different solutions. I ve tried a few and usually end up with my ...

Numbering in jQuery

How could I change the text below so that the text within it has a number appended to it. <div class="right">This is some text</div> <div class="right">This is some text</div>...

热门标签