microsoft / XmlNotepad

XML Notepad provides a simple intuitive User Interface for browsing and editing XML documents.
https://microsoft.github.io/XmlNotepad/
MIT License
980 stars 207 forks source link

Question: handling of TAB andCRLF in saved XSLT-files #198

Open Pierre-de-la-Verre opened 2 years ago

Pierre-de-la-Verre commented 2 years ago

I have a XSLT-file which contains TAB and CRLF-definition to create a better readable output, like this

  <xsl:text>&#0009;</xsl:text>
  <xsl:value-of select="./KEY_NUMERIC_OLD"/>
  <xsl:text>&#0009;</xsl:text>
  <xsl:value-of select="./KEY_NUMERIC_NEW"/>
  <xsl:text>&#xa;</xsl:text>

It works fine, but when I opened the file with XMLNotepad and saved it, all the TABs and CRLF are gone. Why? Related to #166 ?

lovettchris commented 2 years ago

See White space Handling in the XML specification. In this case you may need to use the xml:space="preserve" attribute.

Pierre-de-la-Verre commented 2 years ago

Thanks, but I failed while trying. Can someone give a simple example?

lovettchris commented 11 months ago

Actually I cannot reproduce your problem, there must be something else going on, did the XLST perhaps not honor your request? When I create the attached XML file containing tabs and newlines:

<?xml version="1.0" encoding="utf-8"?>
<root>
    KEY_NUMERIC_OLD KEY_NUMERIC_NEW
    KEY_NUMERIC_OLD KEY_NUMERIC_NEW
    KEY_NUMERIC_OLD KEY_NUMERIC_NEW
    KEY_NUMERIC_OLD KEY_NUMERIC_NEW
</root>

And load it in XML notepad the root element contains this formatted text, nothing changed, when I save the document again the file on disk is still correct, no loss of tabs or newlines in this block of text.

Pierre-de-la-Verre commented 4 months ago

I want to refresh this topic and attach 4 files - one original and 3 derivates:

1) using_tab_codes.xslt: original XSLT, using text with "&#...;"

2) using_tab_codes_xmlint.xslt: created with xmlint.exe -e utf-8 -f -nobom %1; all "&#...;" are gone

3) using_tab_codes_new_no.xslt: opened and saved with XMLNotepad, "Preserve whitespace: no"; all "&#...;" are gone

4) using_tab_codes_new_saved.xslt: opened and saved with XMLNotepad, "Preserve whitespace: yes"; all "&#...;" are replaced with TAB and CR/LF

I'm not sure if 2) and 3) are doing it right ..

xslt_files.zip