Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--
- When a file is transformed using this stylesheet the output will be
- formatted as follows:
- ** Pass #1 **
- 1.) Elements named "info" will be removed
- 2.) Attributes named "file_line_nr" or "file_name" will be removed
- 3.) Comments will be removed
- 4.) Processing instructions will be removed
- 5.) XML declaration will be removed
- 6.) Extra whitespace will be removed
- 7.) Empty attributes will be removed
- 8.) Elements which have no attributes, child elements, or text will be removed
- 9.) All elements will be sorted by name recursively
- 10.) All attributes will be sorted by name
- **Pass #2 **
- 11.) Duplicate sibling elements will be removed
- -->
- <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <!-- Set output options -->
- <xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
- <xsl:strip-space elements="*"/>
- <!--****************************************************************************
- Mode templates
- *****************************************************************************-->
- <xsl:template match="/">
- <!-- First pass with default mode templates -->
- <xsl:variable name="pass1">
- <xsl:apply-templates/>
- </xsl:variable>
- <!-- Second pass with custom de-dup templates -->
- <xsl:apply-templates mode="de-dup" select="$pass1"/>
- </xsl:template>
- <!--****************************************************************************
- Pass #1 / default mode templates
- *****************************************************************************-->
- <!-- Match any attribute -->
- <xsl:template match="@*">
- <xsl:copy/>
- </xsl:template>
- <!-- Match any element -->
- <xsl:template match="*">
- <xsl:copy>
- <xsl:apply-templates select="@*">
- <xsl:sort select="local-name()"/>
- </xsl:apply-templates>
- <xsl:for-each-group group-adjacent="boolean(self::*)" select="node() except (processing-instruction(), comment())">
- <xsl:choose>
- <xsl:when test="current-grouping-key()">
- <xsl:apply-templates select="current-group()">
- <xsl:sort select="local-name()"/>
- <xsl:sort select="."/>
- </xsl:apply-templates>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="current-group()"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each-group>
- </xsl:copy>
- </xsl:template>
- <!-- Elements/attributes to ignore -->
- <xsl:template match="@*[normalize-space()='']|info|@file_line_nr|@file_name|*[not(@*|node())]"/>
- <!--****************************************************************************
- Pass #2 / de-dup mode templates
- *****************************************************************************-->
- <!-- Match any element -->
- <xsl:template match="@*|node()" mode="de-dup">
- <xsl:copy>
- <xsl:apply-templates mode="de-dup" select="@*|node()"/>
- </xsl:copy>
- </xsl:template>
- <!-- Ignore elements which are deep-equal to a preceding sibling element -->
- <xsl:template match="*[some $ps in preceding-sibling::* satisfies deep-equal(., $ps)]" mode="de-dup"/>
- </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement