Your current method works. It is more of a "pull" style stylesheet. The "push" style uses apply-templates.
You could shorten it a bit by using element literals, which makes it a little easier to read:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/array"> <array> <xsl:for-each select="value"> <int> <xsl:value-of select="." /> </int> </xsl:for-each> </array> </xsl:template> </xsl:stylesheet>
A solution using the identity template and a custom template for the value element:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <!--identity template, which copies every attribute and node(element, text, comment, and processing instruction) that it matches and then applies templates to all of it's attributes and child nodes (if there are any) --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <!--Specialized template that matches the value element. Because it is more specific than the identity template above it has a higher priority and will match when the value element is encountered. It creates an int element and then applies templates to any attributes and child nodes of the value element --> <xsl:template match="value"> <int> <xsl:apply-templates select="@*|node()"/> </int> </xsl:template> </xsl:stylesheet>