Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsl - accessing things defined within <xsl:if>

Status
Not open for further replies.

micronoodles

Technical User
Nov 13, 2001
2
US
This bit of xsl takes a letter from A-T (in $MYxaxis) and converts it into a number 0-18 (in $x)

<xsl:variable name=&quot;x&quot; select=&quot;translate($MYxaxis,'ABCDEFGHJKLMNOPQRST','0123456789012345678')&quot; saxon:assignable=&quot;yes&quot;/>
<xsl:if test=&quot;contains('LMNOPQRST',$MYxaxis)&quot;>
<saxon:assign name=&quot;x&quot; select=&quot;($x)+10&quot;/>
</xsl:if>

My question is how can i do the same thing efficiently without using saxon:assign, whilst still having access to $x outside the <xsl:if> statement?

Currently i am in a catch22 where if i define x outside the 'if' i cannot change it inside, and if i define something inside the 'if' i am not able to refer to it outside.
 
In answer to my own question, i have realised it is possible to split up the variable definition, like this -

<xsl:variable name=&quot;tens&quot;>
<xsl:if test=&quot;contains('LMNOPQRST',$MYxaxis)&quot;>
<xsl:value-of select=&quot;10&quot;/>
</xsl:if>
<xsl:if test=&quot;not(contains('LMNOPQRST',$MYxaxis))&quot;>
<xsl:value-of select=&quot;0&quot;/>
</xsl:if>
</xsl:variable>
<xsl:variable name=&quot;x&quot; select=&quot;($tens)+translate($MYxaxis,'ABCDEFGHJKLMNOPQRST','0123456789012345678')&quot;/>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top