Using variable in select of for-each in XSLT

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

  1. bhushansarwade


    Jan 7, 2010
    Likes Received:
    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:eek:utput 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
    bhushansarwade, Jan 7, 2010
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.