XSLT code: HL segments hirachical sequence another alternative code
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" /> <!-- Match the root element and apply templates to its child elements --> <xsl:template match="/"> <M_856> <xsl:apply-templates select="M_856/*" /> </M_856> </xsl:template> <!-- Match specific elements and copy them --> <xsl:template match="S_ST | S_BSN | S_DTM | G_HL[S_HL/D_735='S'] | G_HL[S_HL/D_735='O'] | G_HL[S_HL/D_735='I']"> <xsl:copy-of select="." /> </xsl:template> <!-- Match G_HL elements with additional condition --> <xsl:template match="G_HL[S_HL/D_735='I']"> <xsl:copy-of select="." /> <xsl:copy-of select="../G_HL[S_HL/D_735='P' and S_LIN/D_350...