Created
January 3, 2010 11:40
-
-
Save xokomola/96f351e06ab206b1d423 to your computer and use it in GitHub Desktop.
XSLT identity transforms
This file contains hidden or 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
<!-- From http://ajwelch.blogspot.com/2008/01/identity-transform-for-xslt-20.html --> | |
<xsl:template match="element()"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*,node()"/> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template match="attribute()|text()|comment()|processing-instruction()"> | |
<xsl:copy/> | |
</xsl:template> |
This file contains hidden or 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
<!-- identity template without namespace nodes --> | |
<xsl:template match="*"> | |
<xsl:element name="{ name() }"> | |
<xsl:apply-templates select="@*|node()"/> | |
</xsl:element> | |
</xsl:template> | |
<xsl:template match="@*|text()|comment()|processing-instruction()"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*|node()"/> | |
</xsl:copy> | |
</xsl:template> |
This file contains hidden or 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
<!-- identity template --> | |
<xsl:template match="@*|node()"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*|node()"/> | |
</xsl:copy> | |
</xsl:template> |
This file contains hidden or 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
<xsl:template match="*[count(node())=0]"> | |
<xsl:element name="{ name() }"> | |
<xsl:apply-templates select="@*"/> | |
</xsl:element> | |
</xsl:template> |
This file contains hidden or 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
declare function local:copy($element as element()) { | |
element {node-name($element)} | |
{$element/@*, | |
for $child in $element/node() | |
return if ($child instance of element()) | |
then local:copy($child) | |
else $child | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment