Somewhat verbose version:
Both these might also target the specific internal entity not just "field" but I left it generic since that is all we see in the sample.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="entities">
<entities>
<xsl:apply-templates/>
</entities>
</xsl:template>
<xsl:template match="entity">
<entity>
<xsl:for-each select="*">
<xsl:attribute name="{name()}">
<xsl:value-of select="text()"/>
</xsl:attribute>
</xsl:for-each>
</entity>
</xsl:template>
</xsl:stylesheet>
Output
<entities xmlns="http://www.w3.org/1999/xhtml">
<entity field="13"></entity>
<entity field="1"></entity>
<entity field="5"></entity>
</entities>
Slightly different version with "transform"
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="entities">
<entities>
<xsl:apply-templates/>
</entities>
</xsl:template>
<xsl:template match="entity">
<entity>
<xsl:for-each select="*">
<xsl:attribute name="{name()}">
<xsl:value-of select="text()"/>
</xsl:attribute>
</xsl:for-each>
</entity>
</xsl:template>
</xsl:transform>
Target JUST the field inner elements:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="entities">
<entities>
<xsl:apply-templates/>
</entities>
</xsl:template>
<xsl:template match="entity">
<entity>
<xsl:for-each select="field">
<xsl:attribute name="{name()}">
<xsl:value-of select="text()"/>
</xsl:attribute>
</xsl:for-each>
</entity>
</xsl:template>
</xsl:transform>
Example to do copy and just target the field, no closing tag on entity, also omits the xml declaration.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="entities">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="entity">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="field">
<xsl:attribute name="{name()}">
<xsl:value-of select="text()"/>
</xsl:attribute>
</xsl:template>
</xsl:transform>
Output:
<entities>
<entity field="13"/>
<entity field="1"/>
<entity field="5"/>
</entities>
More Compact version of last one:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="entities|entity">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="field">
<xsl:attribute name="{name()}">
<xsl:value-of select="text()"/>
</xsl:attribute>
</xsl:template>
</xsl:transform>
fieldand use thexsl:attributeinstruction to create an attribute. Alternatively matchentityand use an attribute value template.entities,entity, and one not.