Hello I have a question related to transforming an input XML to an output XML using XSLT and removing the line breaks and indents just for some of the elements.
I would like to illustrate my question:
Input:
<LISTESTOF>
<ICSGROUP>
<ICSNUM>1</ICSNUM>
<ICSDKNAME>A1</ICSDKNAME>
<ICSUKNAME>B2</ICSUKNAME>
</ICSGROUP>
<ICSGROUP>
<ICSNUM>2</ICSNUM>
<ICSDKNAME>B1</ICSDKNAME>
<ICSUKNAME>B2</ICSUKNAME>
</ICSGROUP>
</LISTESTOF>
Output:
<LISTESTOF>
<ICSGROUP><ICSNUM>1</ICSNUM>
<ICSDKNAME>A1</ICSDKNAME>
<ICSUKNAME>B2</ICSUKNAME></ICSGROUP>
<ICSGROUP><ICSNUM>2</ICSNUM>
<ICSDKNAME>B1</ICSDKNAME>
<ICSUKNAME>B2</ICSUKNAME></ICSGROUP>
</LISTESTOF>
My XSLT file so far:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="LISTESTOF">
<xsl:value-of select="'
'" /><LISTESTOF><xsl:apply-templates select="ICSGROUP"/></LISTESTOF>
</xsl:template>
<xsl:template match="ICSGROUP">
<xsl:value-of select="'
'" /><ICSGROUP><xsl:apply-templates select="ICSNUM"/><xsl:value-of select="'
'" /><xsl:apply-templates select="ICSDKNAME"/><xsl:value-of select="'
'" /><xsl:apply-templates select="ICSUKNAME"/></ICSGROUP>
</xsl:template>
<xsl:template match="ICSNUM">
<ICSNUM><xsl:value-of select="."/></ICSNUM>
</xsl:template>
<xsl:template match="ICSDKNAME">
<ICSDKNAME><xsl:value-of select="."/></ICSDKNAME>
</xsl:template>
<xsl:template match="ICSUKNAME">
<ICSUKNAME><xsl:value-of select="."/></ICSUKNAME>
</xsl:template>
</xsl:stylesheet>
Is there a cleaner solution? What will happen with not defined elements? Will they disappear? Any suggestions? Thank you in advance!