Jump to content

xslt return value from template


shwetharaya

Recommended Posts

Hi All,I have to create a template ,where u r passing a parameter inisde the template and matching it with a set of values and if its equal it should return me a yes or no value.is it possible to do.or is there any other way to do it.My problem here is , I have a value to check aganist a set of values for equality i.e to see if the values are same. once it finds any match aganist a set of value .it should return me a value.

Link to comment
Share on other sites

It seems to me as if you haven't assimilated the XSLT tutorial completely. All the tools you need are discussed there:

<xsl:for-each select="node-set to check"><xsl:choose><xsl:when test="condition to check against">yes</xsl:when><xsl:otherwise><!--Things to do if condition fails-->no</xsl:otherwise></xsl:choose></xsl:for-each>
Link to comment
Share on other sites

It seems to me as if you haven't assimilated the XSLT tutorial completely. All the tools you need are discussed there:
i guess u didnt get my question .Let me say I want to check the value 3 aganist a set of values say (1,2,3,4,5,6).so wat i am thinking is i will have a template where i will pass the value 3 from outside to the template where it will check for all these set of values once it matches with the value 3 from the set of values defined in the template it should return me yes or no value. and i want this template to be used for all diffrent values to check and return yes or no value. can u please help on this.
Link to comment
Share on other sites

Well, the idea is almost the same. Create a template with a param, that will serve as the default value. From outside, change that parameter and that's it. For example:

<xsl:param name="test-value" select="'0'"/><xsl:template match="/"><xsl:choose><xsl:when test="$test-value=1">yes</xsl:when><xsl:when test="$test-value=2">double yes</xsl:when><xsl:when test="$test-value=3 or $test-value=4">YEAH!</xsl:when><xsl:otherwise><!--Things to do if all whens fail-->oh no.</xsl:otherwise></xsl:choose></xsl:template>

Even though this stylesheet defines the parameter's value as "0", that value can be changed by the XSLT processors. Methods for doing so vary depenging on the processor and language you're using.

Link to comment
Share on other sites

Well, the idea is almost the same. Create a template with a param, that will serve as the default value. From outside, change that parameter and that's it. For example:
<xsl:param name="test-value" select="'0'"/><xsl:template match="/"><xsl:choose><xsl:when test="$test-value=1">yes</xsl:when><xsl:when test="$test-value=2">double yes</xsl:when><xsl:when test="$test-value=3 or $test-value=4">YEAH!</xsl:when><xsl:otherwise><!--Things to do if all whens fail-->oh no.</xsl:otherwise></xsl:choose>Thanks for the reply ..............<xsl:template match="/"><xsl:variable name="role"><xsl:call-template name="role_checker"><xsl:with-param name="num1" select="8.50"></xsl:withparam></xsl:call-template></xsl:variable><xsl:variable name="role1"><xsl:call-template name="role_checker1">				</xsl:call-template></xsl:variable>value of sum=<xsl:value-of select="$role" /><br/><xsl:if test="$role=1"><xsl:value-of select="catalog/cd/price"/></xsl:if><br/><br/>				value of sum=II <xsl:value-of select="$role1" />II<br/><xsl:if test="$role1=1"><xsl:value-of select="catalog/cd/price"/></xsl:if>								<!--role checker template for exact match-->						 	 </xsl:template>	<xsl:template name="role_checker">	<xsl:param name="num1" />		<xsl:param name="num2"/>					<xsl:for-each select="catalog/cd/price">								<xsl:if test="$num1=.">				   1					</xsl:if>								</xsl:for-each>										</xsl:template>	<!--like match template-->	<xsl:template name="role_checker1">				<xsl:param name="num2"/>									<xsl:for-each select="catalog/cd[starts-with(price,8)]">									1			</xsl:for-each>						</xsl:template></xsl:stylesheet></xsl:template>

Even though this stylesheet defines the parameter's value as "0", that value can be changed by the XSLT processors. Methods for doing so vary depenging on the processor and language you're using.

Well, the idea is almost the same. Create a template with a param, that will serve as the default value. From outside, change that parameter and that's it. For example:
<xsl:param name="test-value" select="'0'"/><xsl:template match="/"><xsl:choose><xsl:when test="$test-value=1">yes</xsl:when><xsl:when test="$test-value=2">double yes</xsl:when><xsl:when test="$test-value=3 or $test-value=4">YEAH!</xsl:when><xsl:otherwise><!--Things to do if all whens fail-->oh no.</xsl:otherwise></xsl:choose>Thanks for the reply ..............<xsl:template match="/"><xsl:variable name="role">  ([color=#FF0000]first variable[/color])<xsl:call-template name="role_checker"><xsl:with-param name="num1" select="8.50"></xsl:withparam></xsl:call-template></xsl:variable><xsl:variable name="role1"><xsl:call-template name="role_checker1">				</xsl:call-template></xsl:variable>value of sum=<xsl:value-of select="$role" /><br/><xsl:if test="$role=1"><xsl:value-of select="catalog/cd/price"/></xsl:if><br/><br/>				value of sum=II <xsl:value-of select="$role1" />II<br/><xsl:if test="$role1=1"><xsl:value-of select="catalog/cd/price"/></xsl:if>								<!--role checker template for exact match-->						 	 </xsl:template>	<xsl:template name="role_checker">	  <xsl:param name="num1" />	  <xsl:param name="num2"/>				<xsl:for-each select="catalog/cd/price">					<xsl:if test="$num1=.">									 1							   </xsl:if>						   </xsl:for-each>								</xsl:template>	<!--like match template-->	<xsl:template name="role_checker1">				<xsl:param name="num2"/>								   <xsl:for-each select="catalog/cd[starts-with(price,8)]">									  1		   </xsl:for-each>						</xsl:template></xsl:stylesheet>THis is my whole code. IN the 1st variable i.e "role"I am trying to match the exact price aganist the list of  price list. but how to send 'N' set of values together to check the values aganist the list of prices.IN the 2nd variable "role1" i am trying to match any variable which starts with price 8. but when i try to capture the 'role1' values it gives me a set of returns values, but i want it returns "yes" or "no" for each match . and then go to test for the 2nd loop. can  u please help me on this. </xsl:template>

Even though this stylesheet defines the parameter's value as "0", that value can be changed by the XSLT processors. Methods for doing so vary depenging on the processor and language you're using.

Link to comment
Share on other sites

Theese "1"s are confusing me a bit... anyway...How to send N values... hm... let's see. You can always add extra parameters and check against them with an "or" like so:

<xsl:if test="$num1=. or $num2=.">

But I guess that's not what you want now, right?I will think about this. It's a really curious thing and I think I might have a hunch.I'm not sure I understand the trouble with role1. Variables are converted to a string, so you can never expect a variable to return a node-set to compare against. And considering the construction of the template, I suppose you get "111111" or more "1"s. One for each cd which price starts with "8". Correct? I still don't see the clear point.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...