nobitavn94 Posted October 15, 2006 Share Posted October 15, 2006 I'm new in XSLT.I want to use avariable to store Id as a parameter like this :<xsl:for-each select="NewDataSet/Table"> <tr> <td style="font-family: Verdana;font-size : 8pt;color:blue"> <xsl:variable name="id" select="Id" /> <xsl:value-of select="Id"/>. </td> <td> <a href="showCatalog.aspx?id='$name'" class="catalogLink" ><xsl:value-of select="Name"/> </a> </td> </tr> </xsl:for-each>but this code doesn't work properly.Can any one help me ?Thanks you very much ! Link to comment Share on other sites More sharing options...
boen_robot Posted October 15, 2006 Share Posted October 15, 2006 First of all, you adress a variable by the value of the name attribute, not the name attribute itself. So you should adress this variable with "$id", not "$name".Also, a local variable (one inside a template) is only available to it's siblings and descendants. Scince in this example the variable is a child of a <td>, it's available only to that <td> and further down.To make it accessable to other cells, simply move it at least one level above. In other words, create it inside a <tr> like this: <xsl:for-each select="NewDataSet/Table"><tr><xsl:variable name="id" select="Id" /><td style="font-family: Verdana;font-size : 8pt;color:blue"><xsl:value-of select="Id"/>.</td><td> <a href="showCatalog.aspx?id='$id'" class="catalogLink" ><xsl:value-of select="Name"/> </a></td></tr> </xsl:for-each> If that for-each generated more then one row, you may even create the variable as a sibling to the row like this: <xsl:for-each select="NewDataSet/Table"><xsl:variable name="id" select="Id" /><tr><td style="font-family: Verdana;font-size : 8pt;color:blue"><xsl:value-of select="Id"/>.</td><td> <a href="showCatalog.aspx?id='$id'" class="catalogLink" ><xsl:value-of select="Name"/> </a></td></tr> </xsl:for-each> Scince all of those are created for each NewDataSet/Table node, the result is the same. Link to comment Share on other sites More sharing options...
nobitavn94 Posted October 16, 2006 Author Share Posted October 16, 2006 First of all, you adress a variable by the value of the name attribute, not the name attribute itself. So you should adress this variable with "$id", not "$name".Also, a local variable (one inside a template) is only available to it's siblings and descendants. Scince in this example the variable is a child of a <td>, it's available only to that <td> and further down.To make it accessable to other cells, simply move it at least one level above. In other words, create it inside a <tr> like this:<xsl:for-each select="NewDataSet/Table"><tr><xsl:variable name="id" select="Id" /><td style="font-family: Verdana;font-size : 8pt;color:blue"><xsl:value-of select="Id"/>.</td><td> <a href="showCatalog.aspx?id='$id'" class="catalogLink" ><xsl:value-of select="Name"/> </a></td></tr> </xsl:for-each> If that for-each generated more then one row, you may even create the variable as a sibling to the row like this: <xsl:for-each select="NewDataSet/Table"><xsl:variable name="id" select="Id" /><tr><td style="font-family: Verdana;font-size : 8pt;color:blue"><xsl:value-of select="Id"/>.</td><td> <a href="showCatalog.aspx?id='$id'" class="catalogLink" ><xsl:value-of select="Name"/> </a></td></tr> </xsl:for-each> Scince all of those are created for each NewDataSet/Table node, the result is the same. I follow your code ,but it doesn't work. Then , the link each text inside td tag like this:"..../showCatalog?id='$id' " . I want $id store <xsl:value-of select="Id"/> value .I wonder if I made mistakes anywhere .Thanks !I follow your code ,but it doesn't work. Then , the link each text inside td tag like this:"..../showCatalog?id='$id' " . I want $id store <xsl:value-of select="Id"/> value .I wonder if I made mistakes anywhere .Thanks ! Link to comment Share on other sites More sharing options...
nobitavn94 Posted October 16, 2006 Author Share Posted October 16, 2006 I follow your code ,but it doesn't work. Then , the link each text inside td tag like this:"..../showCatalog?id='$id' " . I want $id store <xsl:value-of select="Id"/> value .I wonder if I made mistakes anywhere .Thanks ! I follow your code ,but it doesn't work. Then , the link each text inside td tag like this:"..../showCatalog?id='$id' " . I want $id store <xsl:value-of select="Id"/> value .I wonder if I made mistakes anywhere .Thanks ! Link to comment Share on other sites More sharing options...
aalbetski Posted October 16, 2006 Share Posted October 16, 2006 you need to enclose your reference (variable or otherwise) inside of curly braces for this context:"..../showCatalog?id='{$id}' " Link to comment Share on other sites More sharing options...
nobitavn94 Posted October 16, 2006 Author Share Posted October 16, 2006 Thanks again for your explanation ! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now