how could I remove an attribute from tags while I'm sorting and grouping them?
I found how to apply conditional logic while sorting, but not how to combine it with grouping.
My code actually looks like this:
<?xml version="1.0" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:variable name="sortOrder" select="'|IL|CL|BL|INST|CDOL|TL|SL|GL|DL|'" />
<xsl:template match="taskDesc">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:for-each-group select="sectionDesc" group-adjacent="replace(@name, '^(.*)?_[^_]*$', '$1')">
<xsl:perform-sort select="current-group()">
<xsl:sort select="string-length(substring-before($sortOrder,
concat('|', replace(@name, '^.*?_([^_]*$)', '$1'), '|')))"
data-type="number" />
</xsl:perform-sort>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()"> <-- Copy
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
There's an attribute for some sectionDesc
tags called FMOrder
that I need to remove.
This attribute is used in others tags outside taskDesc
, so I can't remove it globally.
Input file example:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FEFExchangeFile>
<!-- Tons of tags -->
<logicConf>
<resource> <!-- Tons of attrs -->
<taskDesc> <!-- Tons of attrs -->
<sectionDesc name="a_b_c_GL" otherstuff="dummy" FMOrder="someothervalue"></sectionDesc>
<sectionDesc name="a_b_c_IL" otherstuff="dummy" FMOrder="somevalue"></sectionDesc>
<!-- Many other tags like this with or without FMOrder attr -->
</taskDesc>
</resource>
</logicConf>
</FEFExchangeFile>