abap-file-formats-tools icon indicating copy to clipboard operation
abap-file-formats-tools copied to clipboard

Escape XML special characters in XSLT transformation enum values

Open Copilot opened this issue 1 week ago • 0 comments

Enum values containing XML special characters (<, >, &, ", ') cause syntax errors in generated XSLT transformations.

Changes

  • Added escape_xml_chars method to zcl_aff_writer_xslt

    • Escapes & first to prevent double-escaping of subsequent replacements
    • Maps: &&#38;, <&#60;, >&#62;, "&#34;, '&#39;
  • Modified get_abap_value method to apply escaping for character and numeric text types

  • Added test coverage for enum values with special characters

Example

Before this fix, an enum like:

BEGIN OF co_enum_values,
  less_than    TYPE c LENGTH 1 VALUE '<',
  greater_than TYPE c LENGTH 1 VALUE '>',
END OF co_enum_values.

Would generate invalid XSLT:

<tt:value ref="FIELD" map="val('<')=xml('lessThan')"/>

Now generates valid escaped XSLT:

<tt:value ref="FIELD" map="val('&#60;')=xml('lessThan')"/>
Original prompt

This section details on the original issue you should resolve

<issue_title>Transformation Generator does not escape special characters</issue_title> <issue_description>XML cannot handle special characters such as '<' and '>'. The generator does not escape these characters which leads to syntax errors in the generated transformation when having an enum/constant like

begin of co_enum_values
   less_than type c length 1 value '<',
   greater_thean type c length 1 value '>',
end of co_enum_values.

A solution would be to replace < with &#60 and > with &#62 in the generated transformation. </issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes SAP/abap-file-formats-tools#319

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Nov 21 '25 15:11 Copilot