2016-12-13 8 views
1

Ich möchte das Plus-Symbol am Ende der Zeile in den einzelnen Satz (single para) einfügen. Ist es möglich, so zu tun?Hinzufügen von Pluszeichen am Ende jeder Zeilenumbruch

Meine XML-Input-Datei ist:

<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> 

I verwendet XSL als

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

Mein Ausgang in den Zeilenumbruch-Modus mit + Symbol sein muss:

"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." 

Ist dieser möglich zu tun? Wenn es so ist, bitte hilf mir dabei. Vielen Dank im Voraus

Antwort

1

Hier wird eine Probe mit Hilfe von XSLT 2.0 und eine Funktion xsl:analyze-string mit einem regulären Ausdruck unter Verwendung eine Zeichenfolge in Stücke einer bestimmten Grenze zu brechen (definiert als Integer-Parameter):

<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> 

Dies verwandelt Ihr Abtastwerteingang in den Ausgang

 "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. 

ich denke, die Funktion zu

verkürzt werden kann
<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> 
+0

"Antwort": "Zusätzliche Probleme mit Ihrer Gesundheit zu entwickeln, die mit Ihrem" + "Diabetes zusammenhängen, ist keineswegs eine ausgemachte Sache. Es gibt viel, was Sie tun können, um Ihr Risiko "+ " zu senken. Indem Sie Ihre Diabetesdiagnose akzeptieren und sich über die "+ " Komplikationen informieren, die auftreten können und wie Sie diese verhindern können, haben Sie bereits einen "+ " wichtigen ersten Schritt gemacht. – User515

+0

anstelle von double quote Ich möchte einzelnes Zitat, wie ich bekommen kann. – User515

Verwandte Themen