XML shredding via XSLT in Java
Here is a generic solution as requested: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output omit-xml-declaration=”yes” indent=”yes”/> <xsl:strip-space elements=”*”/> <xsl:param name=”pLeafNodes” select=”//Level-4″/> <xsl:template match=”https://stackoverflow.com/”> <t> <xsl:call-template name=”StructRepro”/> </t> </xsl:template> <xsl:template name=”StructRepro”> <xsl:param name=”pLeaves” select=”$pLeafNodes”/> <xsl:for-each select=”$pLeaves”> <xsl:apply-templates mode=”build” select=”/*”> <xsl:with-param name=”pChild” select=”.”/> <xsl:with-param name=”pLeaves” select=”$pLeaves”/> </xsl:apply-templates> </xsl:for-each> </xsl:template> <xsl:template mode=”build” match=”node()|@*”> <xsl:param name=”pChild”/> <xsl:param name=”pLeaves”/> <xsl:copy> <xsl:apply-templates mode=”build” select=”@*”/> … Read more