Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Avoid multiple loops >Thread Next - Re: Avoid multiple loops RE: Avoid multiple loopsTo: NULL Date: 1/5/2006 8:22:00 AM This may be a better solution. Rather than having multiple variables for
each attribute it is probably better to store the Items node that has the
maximum atrr1 value then the variable holding the node can be queried for the
other atrr values as and when needed.
Also it's better to move the code to retrieve the maximum atrr1 value to
it's own template reducing the clutter in the main template.
It's done like this:-
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:template match="/Parent">
<xsl:variable name="maxAtrr1">
<xsl:apply-templates select="." mode="getMaxAttr1" />
</xsl:variable>
<xsl:variable name="itemsMax" select="Items[@Atrr1=$maxAtrr1]" />
<result a1="{$itemsMax/@Atrr1}" a2="{$itemsMax/@Atrr2}"
a3="{$itemsMax/@Atrr3}" a4="{$itemsMax/@Atrr4}" a5="{$itemsMax/@Atrr5}"
a6="{$itemsMax/@Atrr6}" />
</xsl:template>
<xsl:template match="Parent" mode="getMaxAttr1">
<xsl:for-each select="Items">
<xsl:sort select="@Atrr1" order="descending" data-type="number" />
<xsl:if test="position()=1">
<xsl:value-of select="@Atrr1"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
