2016-12-13 14 views
1

私は、単一の文(単一パラ)の中で行の折り返しの最後にプラス記号を追加したいと考えています。このようにすることは可能ですか?各行の最後にプラス記号を追加する

私の入力XMLファイルには、次のとおりです。

"response": "Developing additional problems with your health that are related to" + 
    "your diabetes is by no means a foregone conclusion. There is much you can do to" + 
    "lower your risk. By accepting your diabetes diagnosis and educating yourself" + 
    "about the complications that can occur and how to prevent them, you have" + 
"already taken an important first step." 

はこれです:

<response> 
    <p>Developing additional problems with your health that are related to your diabetes is by no means a foregone conclusion. There is much you can do to lower your risk. By accepting your diabetes diagnosis and educating yourself about the complications that can occur and how to prevent them, you have already taken an important first step.</p> 
    </response> 

私は私の出力は、+記号でワードラップモードにする必要が

<xsl:stylesheet version="2.0"> 
     <xsl:template match="response"> 
       "response": "<xsl:apply-templates/>" 
      </xsl:template> 
    </xsl:stylesheet> 

としてXSLを使用できますか?もしそうなら、私を助けてください。ここでは、事前

答えて

1

でいただきありがとうございます(整数パラメータとして定義された)一定限度のチャンクに文字列を分割する正規表現でxsl:analyze-stringを使用してXSLT 2.0と機能を使用したサンプルです:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mf="http://example.com/mf" 
    exclude-result-prefixes="xs mf" version="2.0"> 

    <xsl:param name="length" as="xs:integer" select="80"/> 

    <xsl:param name="pattern" as="xs:string" select="concat('((.{1,', $length, '})(|$))')"/> 

    <xsl:param name="sep" as="xs:string" select="' + &#10;'"/> 

    <xsl:output method="text"/> 

    <xsl:function name="mf:break" as="xs:string"> 
     <xsl:param name="input" as="xs:string"/> 
     <xsl:variable name="result"> 
      <xsl:analyze-string select="$input" regex="{$pattern}"> 
       <xsl:matching-substring> 
        <xsl:value-of select="concat('&quot;', regex-group(2), '&quot;')"/> 
        <xsl:if test="position() ne last()"> 
         <xsl:value-of select="$sep"/> 
        </xsl:if> 
       </xsl:matching-substring> 
      </xsl:analyze-string> 
     </xsl:variable> 
     <xsl:sequence select="$result"/> 
    </xsl:function> 

    <xsl:template match="response"> 
     "response": <xsl:sequence select="mf:break(normalize-space())"/> 
    </xsl:template> 

</xsl:stylesheet> 

これは私が関数が

<xsl:function name="mf:break" as="xs:string"> 
    <xsl:param name="input" as="xs:string"/> 
    <xsl:value-of separator="{$sep}"> 
     <xsl:analyze-string select="$input" regex="{$pattern}"> 
      <xsl:matching-substring> 
       <xsl:sequence select="concat('&quot;', regex-group(2), '&quot;')"/> 
      </xsl:matching-substring> 
     </xsl:analyze-string> 
    </xsl:value-of> 
</xsl:function> 
に短縮することができると思う出力

 "response": "Developing additional problems with your health that are related to your" + 
"diabetes is by no means a foregone conclusion. There is much you can do to lower" + 
"your risk. By accepting your diabetes diagnosis and educating yourself about the" + 
"complications that can occur and how to prevent them, you have already taken an" + 
"important first step. 

にあなたのサンプル入力を変換します

+0

"あなたの健康に関連する" + "糖尿病に関連する問題をさらに発展させることは決して妥当な結論ではありません。あなたのリスクを "+ "に抑えることができます。あなたの糖尿病診断を受け入れ、起こり得る合併症とその予防方法について教えてください。 "+ "の重要な第一歩をすでに取っています。 – User515

+0

二重引用符の代わりに私はどのように得ることができる単一引用符が欲しいです。 – User515

関連する問題