Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: missing line-break when using XSLT identity transformation #379

Closed
Pierre-de-la-Verre opened this issue Apr 10, 2024 · 6 comments

Comments

@Pierre-de-la-Verre
Copy link

It seems that I set a wrong configuration ...

I have a simple "XSLT identity transformation", and using it with xsl.exe it works fine and keeps all line-feeds.

When I use it with XmlNotepad, it transform the file too, but removes all line-feeds. I have to reformat it with xmlint.exe.
I changed all my settings for XmNotepad to "Default" - no solution either.
How can I keep the line-feeds?

@lovettchris
Copy link
Member

Hmm, this one is a bit tricky, if I turn on "Preserve Whitespace" in the XML Document then you will see this:

image

I assume you do not want to see whitespace like this, or do you? In order to have full control over whitespace in the document (and see it in the XSLT transform) you kind of need this, but it's pretty tedious...?

The alternative (1) is I hide all these nodes in the XML notepad UI, but I load the whitespace nodes into the document so XSLT transforms can see the whitespace.

Alternative (2) which saves memory, would be to not load any whitespace into the document, but before I run the XSLT transform I save the document with pretty printing turned on (which xml notepad save is doing already) and then I feed that saved document with whitespace to the XSLT transform. The downside of this is that for very large documents this could add a lot of time before you see the XSLT output due to having to save and reload that doc into the transform.

What is your preference?

@lovettchris
Copy link
Member

lovettchris commented Apr 16, 2024

I ended up adding a new Option under formatting called "Preserve Whitepsace" so you can play with that (in the main branch) and see what you think, after turning it on you will need to reload your XML doc and you will see the above #whitespace nodes.

@Pierre-de-la-Verre
Copy link
Author

Hi Chris
I'm not sure we are talking about the same topic.

I have this XML in UTF-8:

<?xml version="1.0" encoding="utf-8"?>
<DSS_2015_LV95.Siedlungsentwaesserung.Einzugsgebiet TID="12684">
  <OBJ_ID>12684</OBJ_ID>
  <Metaattribute>
    <SIA405_Base_LV95.Metaattribute>
      <Letzte_Aenderung>20211124</Letzte_Aenderung>
    </SIA405_Base_LV95.Metaattribute>
  </Metaattribute>

</DSS_2015_LV95.Siedlungsentwaesserung.Einzugsgebiet>

This XSLT (ident copy):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="@*|node()">
    <xsl:copy >
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

With your xsl.exe 1.0 from your XMLTools 2023-01-27 I use this command:
xsl -s ident_kopie.xslt mini.xml

and get this result:

<?xml version="1.0" encoding="utf-8"?><DSS_2015_LV95.Siedlungsentwaesserung.Einzugsgebiet TID="12684">
  <OBJ_ID>12684</OBJ_ID>
  <Metaattribute>
    <SIA405_Base_LV95.Metaattribute>
      <Letzte_Aenderung>20211124</Letzte_Aenderung>
    </SIA405_Base_LV95.Metaattribute>
  </Metaattribute>

</DSS_2015_LV95.Siedlungsentwaesserung.Einzugsgebiet>

Using the same in XMLNotepad I get this result - with missing line-breaks:

<?xml version="1.0" encoding="utf-8"?><DSS_2015_LV95.Siedlungsentwaesserung.Einzugsgebiet TID="12684"><OBJ_ID>12684</OBJ_ID><Metaattribute><SIA405_Base_LV95.Metaattribute><Letzte_Aenderung>20211124</Letzte_Aenderung></SIA405_Base_LV95.Metaattribute></Metaattribute></DSS_2015_LV95.Siedlungsentwaesserung.Einzugsgebiet>

@lovettchris
Copy link
Member

lovettchris commented Apr 19, 2024

Please re-read my answers, this is about "preserving whitespace" in the XML Document, which XML notepad does not do by default. But xsl.exe does preserve the whitespace by default. Try my new Preserve Whitespace setting and you will get the XSL output you are looking for.

@lovettchris
Copy link
Member

New Preserve Whitespace formatting option is available in https://github.com/microsoft/XmlNotepad/releases/tag/2.9.0.9

@Pierre-de-la-Verre
Copy link
Author

Thanks, works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants