Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Avoid multiple loops [Thread Next] RE: Avoid multiple loopsTo: NULL Date: 1/5/2006 8:12:00 AM In the following XSL the value for the maximum of Atrr1 is used retreive the
same Items node for all the other variables to be assigned.
<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="Var1">
<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:variable>
<xsl:variable name="Var2" select="Items[@Atrr1=$Var1]/@Atrr2" />
<xsl:variable name="Var3" select="Items[@Atrr1=$Var1]/@Atrr3" />
<xsl:variable name="Var4" select="Items[@Atrr1=$Var1]/@Atrr4" />
<xsl:variable name="Var5" select="Items[@Atrr1=$Var1]/@Atrr5" />
<xsl:variable name="Var6" select="Items[@Atrr1=$Var1]/@Atrr6" />
<result a1="{$Var1}" a2="{$Var2}" a3="{$Var3}" a4="{$Var4}" a5="{$Var5}"
a6="{$Var6}" />
</xsl:template>
</xsl:stylesheet>
Anthony
"Praveen" wrote:
> Im doing an xslt transform.
> One of my xml element is like this
> <Parent>
> <Items Atrr1="12" Atrr2="15" Atrr3="82" Atrr4="15" Atrr5="12353"
> Atrr6="1452"/>
> <Items Atrr1="132" Atrr2="15" Atrr3="2" Atrr4="14" Atrr5="1123"
> Atrr6="15452"/>
> <Items Atrr1="142" Atrr2="11" Atrr3="82" Atrr4="31" Atrr5="1223"
> Atrr6="14552"/>
> <Items Atrr1="125" Atrr2="18" Atrr3="8" Atrr4="11" Atrr5="12323"
> Atrr6="1352"/>
> <Items Atrr1="132" Atrr2="155" Atrr3="882" Atrr4="112" Atrr5="1263"
> Atrr6="1252"/>
> <Items Atrr1="12" Atrr2="5" Atrr3="82" Atrr4="16" Atrr5="3"
> Atrr6="15122"/>
> <Items Atrr1="1" Atrr2="15" Atrr3="8122" Atrr4="112" Atrr5="3"
> Atrr6="13452"/>
> <Items Atrr1="12" Atrr2="175" Atrr3="82" Atrr4="41" Atrr5="1223"
> Atrr6="15342"/>
> </Parent>
>
> Im trying to assign Items/@ value to different variable where Items/@Attr1
> is largest.
>
> <xsl:variable name="Var1"><xsl:for-each select="Parent/Items"><xsl:sort
> select="Attr1" sort-order="descending"/>
> <xsl:if test="position()=1"><xsl:value-of
> select="@Attr1"/></xsl:if></xsl:for-each></xsl:variable>
>
> <xsl:variable name="Var2"><xsl:for-each select="Parent/Items"><xsl:sort
> select="Attr1" sort-order="descending"/>
> <xsl:if test="position()=1"><xsl:value-of
> select="@Attr2"/></xsl:if></xsl:for-each></xsl:variable>
> Like this I will be having 6 variables for all attributes.
>
> I want to know is there any better way t o do this. Is it possible to get
> the Node of 'Items' whose @Attr1 is largest to a variable and use that
> variable to read all otehr attributes. How to avoind this multiple loops???
>
>
> thanks
> praveen
>
>
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
