This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Variable access


>  I have a small problem with variable scope.
>  I would like to declare a variable and store the "Cleared" action in the
> <for-each> iteration, and then I have to access it again after
> the loop ends
> (It would be even more nice if I could break the loop on encountering the
> 'Cleared' text) to do some processing based on the status of the
> action. Can
> anyone help me with this?

Hello,

well your main problem, is that you are applying techniques which probably
could be considered bad habit in the xslt world....as always there are
better ways of doing these, its just that you may have to change your
approach


>  Solution needed asap.
>
>   <xsl:template name="Call_ClearedBySystemMapped">
>     <xsl:for-each select="MsgLevel/OIDInfo/OIDMapping">
>       <xsl:if test="ActionString='Cleared'">
> 	<!-- Store the cleared variable here -->
>       </xsl:if>
>     </xsl:for-each>

ok so essentially you want to go through a bunch of elements and 'raise a
generic flag' if some condition is met.

then after this processing, the flag being raised should result in some form
of processing as attributed to your xsl:choose statement.

first step is first why do you have an xsl:for-each ?

do a matching template on your data....dont make a named function first !
something like the following

<xsl:template select="MsgLevel/OIDInfo/OIDMapping">
<xsl:if test="ActionString='Cleared'">

.....ok do something

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

>     <!-- Access the variable here -->
>     <xsl:choose>
>       <xsl:when test="$Action='Cleared'">
>       <xsl:text> YES and process related </xsl:text>
>       </xsl:when>
>       <xsl:otherwise>
>       <xsl:text> NO and do process related </xsl:text>
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:template>

now you could recurse here and call yet another template and yes even a
named template passing a param might be useful...but without seeing all of
your problem....I would then do the processing you desire; which doesnt
require yet another test as in an xsl:choose.

<xsl:template select="MsgLevel/OIDInfo/OIDMapping">
<xsl:if test="ActionString='Cleared'">
            <xsl:text> YES and process related </xsl:text>
</xsl:if>
</xsl:template>

of course if u wanted to handle both conditions you can use an xsl:choose

<xsl:template select="MsgLevel/OIDInfo/OIDMapping">
<xsl:choose>
<xsl:when test="ActionString='Cleared'">
            <xsl:text> YES and process related </xsl:text>
</xsl:when>
<xsl:otherwise>
NO some default processing
</xsl:otherwise>
</xsl:choose>
</xsl:template>


now why didnt your approach work ?

- the scope of your variable was not appropriate..u could have called a
named template from within your xsl:if condition and passed it a
parameter...but once again this is awkward xslt thinking

- you are using techniques which wont get u too far in xslt world.

gl, jim fuller



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]