Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: Avoid multiple loops

From: AnthonyWJones@-----------.---------.---
To: 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 
> 
> 
> 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent