Title: Re: Help! Using variables in for-each

As an alternative approach you could build up the XSL dynamically in Java and not use parameter substitution at all.
--------------------------
Chris Raber, Systems Engineer, AvantGo Inc.
v: 248-554-9330, cell: 810-839-3684
http://www.avantgo.com/
Sent wirelessly using AvantGo Enterprise & RIM!

-----Original Message-----
From: Scott Moore <[EMAIL PROTECTED]>
To: Xalan-J-Users (E-mail) <[EMAIL PROTECTED]>
Sent: Fri Nov 02 09:35:15 2001
Subject: Help!  Using variables in for-each

I'm trying to write a template in xalan that takes a result tree fragment
($root) along with the names of child elements ($col1-select and
$col2-select).  This template would then dynamically create a XSL-FO table
based on the variables passed in.  The template looks something like this:

  <xsl:template name="table-body">
    <xsl:param name="root"/>
    <xsl:param name="col1-select"/>
    <xsl:param name="col2-select"/>
   
    <fo:table-body>
      <xsl:for-each select="$root">
        <fo:table-row>
          <fo:table-cell>
            <fo:block><xsl:value-of select="$col1-select"/></fo:block>
          </fo:table-cell>
          <xsl:if test="string-length($col2-select) > 0">
            <fo:table-cell>
              <fo:block><xsl:value-of select="$col2-select"/></fo:block>
            </fo:table-cell>
          </xsl:if>
        </fo:table-row>
      </xsl:for-each>
    </fo:table-body>
  </xsl:template>

<xsl:call-template name="table-body">
  <xsl:with-param name="root" select="/Session/Values"></xsl:with-param>
  <xsl:with-param name="col1-select">node1</xsl:with-param>
  <xsl:with-param name="col2-select">node2</xsl:with-param>
</xsl:call-template>


It doesn't work.  Instead of treating $col1-select as a XPath _expression_, it
just adds the literal string.  I've tried lots of different expressions

"{$col1-select}"
"./$col1-select"
"self:node()/[name()=$col1-select]"
blah blah

Is this possible?  I think it's probably something simple, but I just can't
figure it out.

Thanks for any help,
Scott

Reply via email to