How to sort specific XML element's group with XSLT? -


how sort group of elements within node of xml file.

here input

<root>     <level_1.1>...</level_1.1>     <level_1.2>...</level_1.2>     <level_1.3>         <sub.1>...</sub.1>         <sub.2>             <s.1>1</s.1>             <s.3>something</s.3>             <s.6>c</s.6>             <s.2/>             <s.4>                 <aa.1>2</aa.1>             </s.4>             <s.5/>         </sub.2>         <sub.3>...</sub.3>     </level_1.3>     <level_1.4>...</level_1.4> </root> 

would have output same hierarchy location below.

<root>     <level_1.1>...</level_1.1>     <level_1.2>...</level_1.2>     <level_1.3>         <sub.2>             <s.1>1</s.1>             <s.2/>             <s.3>something</s.3>             <s.4><aa.1>2</aa.1></s.4>             <s.5/>             <s.6>c</s.6>         </sub.2>         <sub.3>...</sub.3>     </level_1.3>     <level_1.4>...</level_1.4> </root> 

this have tried other's suggestion it's not working.

<xsl:template match="/root/level_1.3"> <xsl:copy>     <xsl:apply-templates>         <xsl:sort select="sub.2" order="ascending"/>     </xsl:apply-templates> </xsl:copy> 

try way?

xslt 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>  <!-- identity transform --> <xsl:template match="@*|node()">     <xsl:copy>         <xsl:apply-templates select="@*|node()"/>     </xsl:copy> </xsl:template>  <xsl:template match="sub.2">     <xsl:copy>         <xsl:apply-templates>             <xsl:sort select="name()" data-type="text" order="ascending"/>         </xsl:apply-templates>     </xsl:copy> </xsl:template>  </xsl:stylesheet> 

Comments