0

HTML ページ用に変換されるテキスト ブロックを解析するために、以下の XSLT テンプレートを作成しました。このテンプレートは複数の場所で使用されていますが、指定した文字が常に正常に変換されません。例は次のとおりです。

「2」に「助け」が欲しいと思い、さらに「4」を探し続けますが、見つけたのは「空」だけです。

その結果、私は「2人」に「助けてもらいたい」と思い、「もっと」を探し続けましたが、見つけたのは「空」だけでした。

何かご意見は?

<xsl:template name="PreserveQuotations">
  <xsl:param name="text"/>
  <xsl:choose>
    <xsl:when test="contains($text,'&#8220;')">
      <xsl:value-of select="substring-before($text,'&#8220;')"/>
      <xsl:text>"</xsl:text>
      <xsl:call-template name="PreserveQuotations">
        <xsl:with-param name="text">
          <xsl:value-of select="substring-after($text,'&#8220;')"/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="contains($text,'&#8221;')">
      <xsl:value-of select="substring-before($text,'&#8221;')"/>
      <xsl:text>"</xsl:text>
      <xsl:call-template name="PreserveQuotations">
        <xsl:with-param name="text">
          <xsl:value-of select="substring-after($text,'&#8221;')"/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$text"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
4

1 に答える 1

0

次の形式の文字列の場合について考えると、問題は明らかになるはずです。

aaa &#8221; bbb &#8220; ccc

明らかな解決策が 2 つあります。(1) 文字列に両方の特殊文字が含まれている場合をチェックし、最初に発生した文字を処理します。または (2) 文字ごとに文字列を 1 回パスします。(テンプレートを 2 つのテンプレートに分割するか、パラメーターで検索する文字を指定します。)

于 2012-12-21T16:45:31.747 に答える