1

I'm using data from a MySQLi query and placing it into an XSLT file that eventually replaces the document.xml file in Word. The issue I am having is with \r and \n coming into my Word document.

The XSLT files are quite large so I will not paste all the code here, however, an example of one of the fields is below:

            <w:p w:rsidR="00C61454" w:rsidRPr="00430555" w:rsidRDefault="00AE5B7C" w:rsidP="00C61454">
              <w:pPr>
                <w:rPr>
                  <w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:cs="Segoe UI"/>
                </w:rPr>
              </w:pPr>
              <w:proofErr w:type="spellStart"/>
              <w:r w:rsidRPr="00AE5B7C">
                <w:rPr>
                  <w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:cs="Segoe UI"/>
                  <w:sz w:val="18"/>
                  <w:szCs w:val="18"/>
                </w:rPr>
                <w:t><xsl:value-of select="comments"/></w:t>
              </w:r>
              <w:proofErr w:type="spellEnd"/>
            </w:p>

In the above code, comments is being placed from the mysqli query into the xslt. There are a few other fields that may contain \r\n so something that works for the entire file would be best.

If doing a replace in the SELECT script works, I can take that route too, however, being a novice, I wouldn't know how to replace multiple items (the \r and the \n), nor what to replace them with to create the line feed / carriage return in Word.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Michael
  • 159
  • 10
  • You need to tell us what version of XSLT you are using. Also, if you don't know what output you want to generate, then this isn't an XSLT coding problem. – Michael Kay Jul 03 '18 at 22:32

1 Answers1

0

In XSLT/XPath, normalize-space() will consolidate embedded whitespace and trim surrounding whitespace. Perhaps it could help with your unwanted \r\n characters.

See also How to add a newline (line break) in XML file? (Semantics of newline and line break characters can depend upon the processing application.)

Finally, in OOXML (the markup standard behind Microsoft Word's DOCX format), use <w:br/> (between w:t text elements within w:r run elements) to force a hard line break.

kjhughes
  • 106,133
  • 27
  • 181
  • 240