Sorting on one attribute removes another attribute from xml file



I want sort the xml data based on count attribute and select first 100 values.


I have written this xsl. But it is removing @code from indicator tag which is required for further processing.



<xsl:template match="node()|@*">
<xsl:if test="//field[count(indicators/indicator/values) &lt; '100' or count(subfields/subfield/position/values) &lt; '100']">
<xsl:copy>

<xsl:apply-templates select="node()|@*">
<xsl:sort select="@count" data-type="number" order="descending"/>
</xsl:apply-templates>

</xsl:copy>
</xsl:if>
</xsl:template>


The xml data is :



<field count="3159" tag="461">
<indicators>
<indicator code="1">
<values count="3159" value=" " />
</indicator>
<indicator code="2">
<values count="3159" value="1" />
</indicator>
</indicators>
<subfields>
<subfield code="3" count="3497">
<position>
<values count="1" value="200000000120020805151840" />
<values count="28" value="200000000220020805151840" />
<values count="32" value="200000190420020805152452" />
<values count="8" value="200000190520020805152453" />
<values count="1" value="200000190620020805152453" />
<values count="9" value="200000190720020805152453" />
<values count="6" value="200000190820020805152454" />
<values count="3" value="200000190920020805152454" />
</position>
</subfield>
</subfields>
</field>


Please help to find 100 highest values and @code attribute which is removed after sorting from indicator tag.


No comments:

Post a Comment