Created
January 28, 2011 15:04
-
-
Save vicmortelmans/800354 to your computer and use it in GitHub Desktop.
templates for flattening a purely hierarchical XML structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- templates for flattening a purely hierarchical XML structure | |
into a list of <item> records --> | |
<xsl:template match="*" mode="flatten"> | |
<xsl:apply-templates mode="flatten"/> | |
</xsl:template> | |
<xsl:template match="*[not(*)]" mode="flatten"> | |
<!-- working upwards starting from leaf nodes --> | |
<item> | |
<xsl:apply-templates select="." mode="flatten-ancestor"/> | |
</item> | |
</xsl:template> | |
<xsl:template match="*" mode="flatten-ancestor"> | |
<xsl:copy> | |
<xsl:copy-of select="@*"/> | |
</xsl:copy> | |
<xsl:apply-templates select="ancestor::*[1]" mode="flatten-ancestor"/> | |
</xsl:template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool, thanks! It's not what I needed, though... but I have already found what I was looking for.