Using variable in select of for-each in XSLT

Discussion in 'Software' started by bhushansarwade, Jan 7, 2010.

  1. bhushansarwade

    bhushansarwade

    Joined:
    Jan 7, 2010
    Messages:
    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"?>
    <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:eek:utput 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
    bhushansarwade, Jan 7, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cameron

    XSLT programming

    cameron, Jan 4, 2004, in forum: Firefox
    Replies:
    0
    Views:
    498
    cameron
    Jan 4, 2004
  2. juanita_guiterrez

    xslt/xpath string manipulation

    juanita_guiterrez, Jul 29, 2006, in forum: Software
    Replies:
    0
    Views:
    1,534
    juanita_guiterrez
    Jul 29, 2006
  3. arumahi
    Replies:
    0
    Views:
    1,026
    arumahi
    Sep 3, 2007
  4. h_q
    Replies:
    0
    Views:
    1,068
  5. Giuen
    Replies:
    0
    Views:
    664
    Giuen
    Sep 12, 2008
Loading...

Share This Page