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

Task XslTransformation: How to specify XmlSpace.Preserve? #7671

Closed
NMertsch opened this issue Jun 3, 2022 · 3 comments · Fixed by #7716
Closed

Task XslTransformation: How to specify XmlSpace.Preserve? #7671

NMertsch opened this issue Jun 3, 2022 · 3 comments · Fixed by #7716
Labels
Area: Tasks Issues impacting the tasks shipped in Microsoft.Build.Tasks.Core.dll. Feature Request Good First Issue Self-contained issues good for first-time contributors. help wanted Issues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim. triaged
Milestone

Comments

@NMertsch
Copy link

NMertsch commented Jun 3, 2022

Issue Description

The MSBuild Task XslTransformation (docs, source) always loads the provided XSLT file with XmlSpace.Default. I would like to use XmlSpace.Preserve instead.

Steps to Reproduce

See this project. It contains an XSL stylesheet, an input XML file, and a dotnet project that generates two output files: one with the XslTransformation task, one in Program.cs. It also contains both output files so you can see the difference in GitHub.

You can clone the repo, delete the generated files, and run dotnet run to re-generate them.

Expected Behavior

Both files have the same content.

Actual Behavior

The MSBuild Task does not preserve whitespace and offers no way to change this behavior (at least none that I was able to find).

Analysis

The desired behavior can be achieved by changing new XPathDocument(reader) to new XPathDocument(reader, XmlSpace.Preserve) in this line.

I'm happy that XmlSpace.Default is the default. But I'd like to have an option to use XmlSpace.Preserve instead, e.g. via <XslTransformation PreserveWhitespace="true" ... />.

Versions & Configurations

To reproduce this, I use the dotnet CLI without IDE.

  • dotnet --version: 6.0.300
  • OS: Windows 10 Pro (Version 10.0.19044 Build 19044)
@NMertsch NMertsch added bug needs-triage Have yet to determine what bucket this goes in. labels Jun 3, 2022
@NMertsch NMertsch changed the title XslTransformation ignores whitespace output Task XslTransformation ignores whitespace-only xsl:text elements Jun 3, 2022
@NMertsch NMertsch changed the title Task XslTransformation ignores whitespace-only xsl:text elements Task XslTransformation: How to specify XmlSpace.Preserve? Jun 8, 2022
@rainersigwald
Copy link
Member

Team triage: Nice analysis! We would accept a new argument to the task that passes a bool down to that call.

@rainersigwald rainersigwald added Feature Request Area: Tasks Issues impacting the tasks shipped in Microsoft.Build.Tasks.Core.dll. Good First Issue Self-contained issues good for first-time contributors. and removed bug needs-triage Have yet to determine what bucket this goes in. labels Jun 16, 2022
@rainersigwald rainersigwald added this to the Backlog milestone Jun 16, 2022
@rainersigwald rainersigwald added the help wanted Issues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim. label Jun 16, 2022
@shadyalfred
Copy link
Contributor

shadyalfred commented Jun 18, 2022

Are the parameters specified in the .csproj file automatically mapped to the XslTransformation class? Because I couldn't find how they're read, except in the test files where the properties of XslTransformation are manually assigned. Am I correct in guessing that only adding a boolean property (which changes the behavior of XPathDocument) to XslTransformation is enough? However, adding a new property to the XslTransformation class gives an error

error RS0016: Symbol 'PreserveWhitespace.get' is not part of the declared API

Update: fixed it by modifying the public API files

shadyalfred added a commit to shadyalfred/msbuild that referenced this issue Jun 18, 2022
`PreserveWhitespace` option to use `XmlSpace.Preserve` with
`XPathDocument`.
@rainersigwald
Copy link
Member

Are the parameters specified in the .csproj file automatically mapped to the XslTransformation class? Because I couldn't find how they're read, except in the test files where the properties of XslTransformation are manually assigned. Am I correct in guessing that only adding a boolean property (which changes the behavior of XPathDocument) to XslTransformation is enough?

That's correct; there is some documentation on task invocation and if you want the details you might be interested in TaskExecutionHost.SetTaskParameters.

However, adding a new property to the XslTransformation class gives an error

error RS0016: Symbol 'PreserveWhitespace.get' is not part of the declared API

Update: fixed it by modifying the public API files

That was almost perfect; I'm making a suggestion in your PR.

Forgind pushed a commit that referenced this issue Jul 20, 2022
PreserveWhitespace option to use XmlSpace.Preserve with
XPathDocument.

Fixes #7671

Context
Should fix whitespace issue with XSLT files

Changes Made
Adding a new public property to the class XslTransformation. If it PreserveWhitespace is set to true, the produced file will preserve whitespaces.
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Tasks Issues impacting the tasks shipped in Microsoft.Build.Tasks.Core.dll. Feature Request Good First Issue Self-contained issues good for first-time contributors. help wanted Issues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim. triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants