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

Altered formatting of original XML #224

Open
boudhayan-dev opened this issue Sep 11, 2023 · 0 comments
Open

Altered formatting of original XML #224

boudhayan-dev opened this issue Sep 11, 2023 · 0 comments

Comments

@boudhayan-dev
Copy link

Hi,

We are using jcabi-xml to perform XML -> HTML conversion using XSLT files. The issue, that we have noticed is that -
The original formatting of the XML is altered (whitespaces included in between each tag) and therefore the resultant HTML conversion using XSLT files results in unnecessary whitespaces in the documentation.

Questions -

  1. Is that the expected behavior?
  2. If yes, is there a configuration to preserve the original whitespace/formatting such that the resultant HTML Conversion does not differ from the XML document?

Following are some code snippets being used -

  1. General flow of XML to HTML Conversion -
	public String convertToHtml(String xsltString, String xmlString) {
		XSLDocument xsltDocument = new XSLDocument(xsltString);
		XMLDocument xmlDocument = new XMLDocument(xmlString);
		return xsltDocument.applyTo(xmlDocument);
	}
  1. Sample XML in string format -
<p>Copy the value: XYZ_<ph id="id1"><varname id="id2">dynamicText</varname></ph>_SUFFIX123 in the System tab</p>
  1. The XML document when deserialized into XMLDocument object -
<p> Copy the value: XYZ_ <ph id="id1"><varname id="id2"> dynamicText </varname></ph> _SUFFIX123 in the System tab </p>

As you can see, there are extra spaces added in the XMLDocument object's content.

  1. The XSLDocument (XSLT) object's cotnent also has the same issues i.e. extra whitespaces and line breaks added.

A section in XSLT that performs the transformation of the varname section -

<xsl:when test="contains(@id, 'cdrtype_Value_Lookup')">
	<span>
		<xsl:attribute name="class">cdrcontrol cdrcontrol-Value_Lookup</xsl:attribute>
		<xsl:attribute name="cdrtype">Value_Lookup</xsl:attribute>
		<xsl:if test="contains(@id, 'cdrtype_Value_Lookup_')">
				<xsl:attribute name="cdrhref">
				<xsl:choose>
					<xsl:when test="contains(@id,'@')">
					<xsl:value-of
					select="substring-after(@id,'@')" />								
					</xsl:when>
					........
					
					<xsl:when test="contains(@id, 'CIAS.')">
						<xsl:value-of
						select="substring-after(@id,'cdrtype_Value_Lookup_')" />
					</xsl:when>								
				</xsl:choose>
			</xsl:attribute>
			<xsl:attribute name="cdrdita">varname</xsl:attribute>
		</xsl:if>
		<xsl:value-of select="." />
	</span>
</xsl:when>
  1. Finally, when the transformation is applied appliedTo(), the resultant HTML also has extra spaces.

This affects our use cases which end up having unncessary spaces.

Example -
Copy the value: XYZ_ dynamicText _SUFFIX123 in the System tab
instead of
Copy the value: XYZ_dynamicText_SUFFIX123 in the System tab

If you can provide insights on how to deal with the content changes, it'll be really helpful.
Thanks in advance.

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

No branches or pull requests

2 participants