i am a newbie and xslt and i created an xslt for my xml to XML transformation that sorts a field called catLineNum.
XSLT code
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:array="http://www.w3.org/2005/xpath-functions/array"
exclude-result-prefixes="#all"
version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="category">
<category><xsl:value-of select= "category"/></category>
<xsl:variable name="min" select="min(//catLineNum)" />
<catLineNum><xsl:value-of select="$min" /></catLineNum>
<xsl:copy>
<xsl:apply-templates select="categoryDescription">
<xsl:sort select="catLineNum" data-type="number" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
input xml
<?xml version='1.0' encoding='UTF-8'?>
<root>
<model>
<models>
<key>18322022AMECHANICAL & PERFORMANCE</key>
<models>
<category>
<category>MECHANICAL & PERFORMANCE</category>
<categoryDescription>
<categoryDescription>with Valvematic Technology, CVT</categoryDescription>
<catLineNum>002</catLineNum>
</categoryDescription>
<categoryDescription>
<categoryDescription>-15-in Styled Steel Wheels</categoryDescription>
<catLineNum>003</catLineNum>
</categoryDescription>
<categoryDescription>
<categoryDescription>-1.8L 4-cyl Engine</categoryDescription>
<catLineNum>001</catLineNum>
</categoryDescription>
</category>
</models>
</models>
</model>
</root>
output
<?xml version="1.0" encoding="UTF-8"?>
<root>
<model>
<models>
<key>18322022AMECHANICAL & PERFORMANCE</key>
<models>
<category>MECHANICAL & PERFORMANCE</category>
<catLineNum>1</catLineNum>
<category>
<categoryDescription>
<categoryDescription>-1.8L 4-cyl Engine</categoryDescription>
<catLineNum>001</catLineNum>
</categoryDescription>
<categoryDescription>
<categoryDescription>with Valvematic Technology, CVT</categoryDescription>
<catLineNum>002</catLineNum>
</categoryDescription>
<categoryDescription>
<categoryDescription>-15-in Styled Steel Wheels</categoryDescription>
<catLineNum>003</catLineNum>
</categoryDescription>
</category>
</models>
</models>
</model>
</root>
The problem is that if I don't include this part of code
<xsl:template match="category"> <xsl:value-of select= "category"/>
the category field will be missing in the output. I feel that there is another way to do it just sort the values and include that category field. Thank you for your help.