2017-11-23 4 views
0

私は1つのシナリオで助けが必要です:テキスト内にスペース、ハイフン、またはフルストップ文字が最後に出現する前に部分文字列を入力する必要があります。部分文字列を前に試しましたXSLT2.0でのサブストリング

たとえば、テキストが 'SIR WILLIAM SIEMENS SQUARE'の場合、最初の文字列と 'SQUARE'として 'SIR WILLIAM SIEMENS'が必要です。 'SIR'と 'WILLIAM SIEMENS SQUARE'を取得する前にサブストリングを使用する。

答えて

0

まず - スペースとし、それが動作します(と。)。このようにしてみてください。

<xsl:template match="/"> 
    <root> 
     <xsl:variable name="maintext" select="replace(replace(/root/a, '\.', '. '), '-', '- ')"/> 
     <a><xsl:value-of select="tokenize($maintext, ' ')[position() != last()]"/></a> 
     <b><xsl:value-of select="tokenize($maintext, ' ')[last()]"/></b> 
    </root> 
</xsl:template> 
+0

ありがとう、それは今働いています。 – Siddharth

0

あなたは次のように実行する必要があります。あなたが交換する必要が

<xsl:template match="/"> 
    <a><xsl:value-of select="tokenize(., ' ')[position() != last()]"/></a> 
    <b><xsl:value-of select="tokenize(., ' ')[last()]"/></b> 
</xsl:template> 
+0

感謝を使用することができますが、私のシナリオでは、私は宇宙の最後に出現する、つまりハイフンまたは完全に停止する前にサブストリングにする必要があります。たとえば、テキストが 'SIR WILLIAM SIEME N.SSQUARE'の場合、 'SIR WILLIAM SIEME N'という部分文字列にする必要があります。と 'SSQUARE' – Siddharth

0

あなたも分析し、文字列

<xsl:template match="/"> 
    <xsl:analyze-string select="normalize-space(.)" regex="(.+[\W])([\w]+)"> 
     <xsl:matching-substring> 
      <a><xsl:value-of select="normalize-space(regex-group(1))"/></a> 
      <b><xsl:value-of select="regex-group(2)"/></b> 
     </xsl:matching-substring> 
     <xsl:non-matching-substring> 
      <xsl:value-of select="."/> 
     </xsl:non-matching-substring> 
    </xsl:analyze-string> 
</xsl:template>