Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > Using variable in select of for-each in XSLT

Thread Tools

Using variable in select of for-each in XSLT

bhushansarwade bhushansarwade is offline
Junior Member
Join Date: Jan 2010
Posts: 1
Hello all,
I am trying to dynamically access the bunch of tag set from my XML file in XSLT to generate a desired HTML file, but struck at some point. The XML looks like

<?xml version="1.0"?>
<title colspan="2">Region A</title>
<title colspan="2">Region B</title>
<title colspan="3">Prod Cat 1</title>
<title colspan="3">Prod Cat 2</title>
<title colspan="2">Prod Cat 3</title>
<title rowspan="3">MH</title>

and the XSLT is

<xsl:output method="html" indent="yes" />
<xsl:template match="/">
<table border="1" width="100%">
<xsl:call-template name="h-title">
<xsl:with-param name="j">1</xsl:with-param>
<xsl:with-param name="i"><xsl:value-of select="matrix/x-depth" /></xsl:with-param>

<xsl:template name="v-depth">
<xsl:param name="count" />
<xsl:if test="$count &gt; 0"><th bgcolor="DarkGray"></th></xsl:if>
<xsl:if test="$count &gt; 0">
<xsl:call-template name="v-depth">
<xsl:with-param name="count"><xsl:value-of select="$count - 1" /></xsl:with-param>

<xsl:template name="h-title">
<xsl:param name="j" />
<xsl:param name="i" />
<xsl:if test="$j &lt;= $i">
<xsl:call-template name="v-depth">
<xsl:with-param name="count"><xsl:value-of select="/matrix/y-depth" /></xsl:with-param>
<xsl:variable name="concat_path" select="concat('/matrix/h/h',$j,'/title')" />
<!--<td><xsl:value-of select="$concat_path" /></td>-->
<xsl:for-each select="$concat_path">
<xsl:value-of select="current()" />
<xsl:if test="$j &lt;= $i">
<xsl:call-template name="h-title">
<xsl:with-param name="j"><xsl:value-of select="$j + 1" /></xsl:with-param>
<xsl:with-param name="i"><xsl:value-of select="$i" /></xsl:with-param>

When I assign a hard coded value, like "matrix/h/h1/title", to "concat_path" variable and refer that variable in select of for-each, everything works fine. But the problem is when I use concat() function in the "concat_path" variable it gives an error, which is an uncaught error. I am not getting what is wrong... please any suggestion is appreciable
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
select gridview row without using select button? =?Utf-8?B?RGFiYmxlcg==?= ASP .Net 5 02-27-2009 02:56 AM
Filtering the output using select attribute from XML file in XSLT XML 1 11-05-2007 10:06 PM
Multiple XSLT Transforms using a Controller XSLT XML 2 10-19-2005 11:00 AM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM
[XSLT]Passing values from Javascript to a XSLT variable Benjamin Hillsley XML 3 09-25-2003 04:50 AM