Subject: RE: Sort Question
From: "Simon, Jb" <jb.simon@xxxxxxxx>
Date: Mon, 06 Jun 2005 10:57:26 -0400
|
> -----Original Message-----
> From: omprakash.v@xxxxxxxxxxxxx [mailto:omprakash.v@xxxxxxxxxxxxx]
> Sent: Thursday, June 02, 2005 3:57 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: Sort Question
>
<snip>
> Next, the Range_Type should be
>
> RANGE_TYPE ( UINT8, ColorType, Red, White ) ;
>
> I can't for the life of me figure out how to restucture the template
>
> <xsl:template match="tblEnumeratedTypes_WC"
mode="range-macro">
>
>
> Ans: This one was a lot tougher. My original idea was to store the
sorted
> nodes in a variable and access the nodes using xpath expressions. But
this
> didn't work as I found out to my surprise that the text output method
> does
> not allow you create elements not even create them and bind them to a
> variable. Then I found the match template for tblEnumValues_WC node
was
> being called in sorted order and used position() arrive at the desired
> result. However, the stylesheet needs to receive the position of the
last
> node as a parameter or needs to compute it in a previous pass to allow
the
> stylesheet to scale.
>
>
> Hope this helps.
>
> Cheers,
> prakash
>
>
>
> <xsl:template match="tblEnumValues_WC" mode="makecopy">
>
>
> <xsl:choose>
> <xsl:when test="position() = 1">
> <xsl:variable name="Start">
> <xsl:call-template
name="removeSpaces">
> <xsl:with-param name="text"
> select="EnumValueDescription"/>
> </xsl:call-template>
> </xsl:variable>
>
> <xsl:value-of select="$Start"/>
>
> </xsl:when>
> <xsl:when test="position() = last()">
> <xsl:variable name="End" >
> <xsl:call-template name="removeSpaces">
> <xsl:with-param name="text"
> select="EnumValueDescription"/>
> </xsl:call-template>
> </xsl:variable>
>
> , <xsl:value-of select="$End"/>) ;
>
> </xsl:when>
> <xsl:otherwise>
>
> </xsl:otherwise>
> </xsl:choose>
>
>
Prakash,
The above stylesheet works fine as long as there are more than 1 nodes.
If there is only one than below statement
> <xsl:when test="position() = last()">
Never gets evaluated. I am attempting to repair this now... any ideas ?
What I was thinking was something along the lines of the following
pseudo code, although I do not know how to implement it in xsl. I hope
the following makes some sense !
lastParameterWritten=false
Choose
When test="position()=1"
Write first parameter
End when
When test="position()=last()"
Write last parameter
Set lastParameterWritten = true
End when
End Choose
If test="lastParameterWritten=false"
Write currentParameter as last
End if
Thanks
Joe
|