Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Using variable in select of for-each in XSLT

 
 
bhushansarwade bhushansarwade is offline
Junior Member
Join Date: Jan 2010
Posts: 1
 
      01-07-2010
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"?>
<matrix>
<x-depth>3</x-depth>
<y-depth>2</y-depth>
<number-of-measure>2</number-of-measure>
<h>
<h1>
<title colspan="2">Region A</title>
<title colspan="2">Region B</title>
</h1>
<h2>
<title colspan="3">Prod Cat 1</title>
<title colspan="3">Prod Cat 2</title>
<title colspan="2">Prod Cat 3</title>
</h2>
<h3>
<title>p1</title>
<title>p2</title>
<title>p3</title>
<title>p4</title>
<title>p5</title>
<title>p6</title>
<title>p7</title>
<title>p8</title>
</h3>
<r1>
<title rowspan="3">MH</title>
</r1>
<r2>
<title>Pune</title>
<title>Mumbai</title>
<title>Aurangabad</title>
</r2>
</h>
</matrix>

and the XSLT is

<xsl:output method="html" indent="yes" />
<xsl:template match="/">
<div>
<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:call-template>
</table>
</div>
</xsl:template>

<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:call-template>
</xsl:if>
</xsl:template>

<xsl:template name="h-title">
<xsl:param name="j" />
<xsl:param name="i" />
<xsl:if test="$j &lt;= $i">
<tr>
<xsl:call-template name="v-depth">
<xsl:with-param name="count"><xsl:value-of select="/matrix/y-depth" /></xsl:with-param>
</xsl:call-template>
<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">
<th>
<xsl:value-of select="current()" />
</th>
</xsl:for-each>
</tr>
</xsl:if>
<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>
</xsl:call-template>
</xsl:if>
</xsl:template>



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
 
 
 
Reply

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 itssri.srinivas@gmail.com XML 1 11-05-2007 10:06 PM
Multiple XSLT Transforms using a Controller XSLT sneill@mxlogic.com 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



Advertisments