2017-12-22 16 views
-2

私はそれぞれXMLで"'で単一/二重引用符を置き換える変換しようとしていますに代わるXSLTバージョン1シングル/ダブルクォート

私は誰かが助けることができるのであれば非常に感謝し、XSLするのは非常に新しいです

+4

これまでに試したことの例を挙げてください。 –

+0

以下の回答をご覧ください。あなたの将来の質問のために、他のユーザからの「ダウン投票」を避けるために、より多くの入力データを具体的な要件で提供してください。 –

答えて

0

ダイナミックな置換方法の場合は、入力テキストとしてパラメータを持つ別々のテンプレートを作成し、置き換えるものと置き換えるものを作成する方がよいでしょう。

ので、この例では入力テキストは次のとおりです。

Your text "contains" some "strange" characters and parts. 

XSLの例以下では、 "( ')"'"()" の交換を参照できます。次に

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="text"/> 
    <!--template to replace--> 
    <xsl:template name="template-replace"> 
     <xsl:param name="param.str"/> 
     <xsl:param name="param.to.replace"/> 
     <xsl:param name="param.replace.with"/> 
     <xsl:choose> 
      <xsl:when test="contains($param.str,$param.to.replace)"> 
       <xsl:value-of select="substring-before($param.str, $param.to.replace)"/> 
       <xsl:value-of select="$param.replace.with"/> 
       <xsl:call-template name="template-replace"> 
        <xsl:with-param name="param.str" select="substring-after($param.str, $param.to.replace)"/> 
        <xsl:with-param name="param.to.replace" select="$param.to.replace"/> 
        <xsl:with-param name="param.replace.with" select="$param.replace.with"/> 
       </xsl:call-template> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:value-of select="$param.str"/> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 

    <xsl:template match="/"> 
     <xsl:call-template name="template-replace"> 
      <!--put your text with quotes--> 
      <xsl:with-param name="param.str">Your text "contains" some "strange" characters and parts.</xsl:with-param> 
      <!--put quote to replace--> 
      <xsl:with-param name="param.to.replace">"</xsl:with-param> 
      <!--put quot and apos to replace with--> 
      <xsl:with-param name="param.replace.with">"'</xsl:with-param> 
     </xsl:call-template> 
    </xsl:template> 
</xsl:stylesheet> 

交換結果は次のようになります。

Your text "'contains"' some "'strange"' characters and parts. 

希望するlp。