tags:

views:

1322

answers:

2

In an existing XSL stylesheet I was passing a string into a named template. Due to a requirements change, I now need to display four strings, the string I was displaying and its three siblings. Rather than pass the four separate strings into the named template, I'm trying to pass their parent element (PETrailingFund in the code below),

 <xsl:call-template name="row">
  <xsl:with-param name="label">Price/Earnings Trailing</xsl:with-param>
  <xsl:with-param name="formatMarker">x</xsl:with-param>
  <xsl:with-param name="fund" select="PETrailingFund" />
  <xsl:with-param name="benchmark">
    <xsl:value-of select="benchmark/PETrailingBenchmark"/>
  </xsl:with-param>
  <xsl:with-param name="benchmark2">
    <xsl:value-of select="benchmark2/PETrailingBenchmark"/>
  </xsl:with-param>
</xsl:call-template>

but the transformation blows up when I try to work with the "fund" parameter in the named template:

<xsl:template name="row">
  <xsl:param name="label" />
  <xsl:param name="fund" />
  <xsl:param name="benchmark">NOT PROVIDED</xsl:param>
  <xsl:param name="benchmark2">NOT PROVIDED</xsl:param>
  <xsl:param name="formatMarker">&#160;</xsl:param>
  <xsl:param name="useDecimalFormatter">yes</xsl:param>
  <tr>
    <td class="first popup">
      <xsl:value-of select="$label" disable-output-escaping="yes"/>
    </td>
    <td>
      <xsl:if test="$benchmark = 'NOT PROVIDED'">
        <xsl:attribute name="class">last</xsl:attribute>
      </xsl:if>
      <xsl:value-of select="$fund/child::*" />
      <xsl:value-of select="$formatMarker"/>
    </td>
  </tr>
</xsl:template>

From what I've read, I'm not really passing in a node but a result tree fragment and I need to get it back to a node (or node-set). Is that accurate or am I doing something else wrong? How would I convert it (I'm working in a fairly stock PHP5 environment that I can't change).

N.B., I trimmed a good bit of the named template for simplicity's sake.

A: 

Instead of doing an

<xsl:call-template..>

, have you instead tried to do an

<xsl:apply-templates..>

on the node or node set in question?

Keith
You can't call a named template with apply-templates. Am I missing something?
Tom
Correct, you can't. I was just recommending you recode the template with match="YourNode" instead of a named template. I believe you can still pass params to this as well.
Keith
Unfortunately, I can't do that as I'm using the template against a number of different nodes.
Tom
Sure you can: <xsl:template match="YourNode1|YourNode2|YourNode3">
Keith
Sorry, not quite what I meant. I know you can have it match different nodes, but I want to control when it gets called.
Tom
+2  A: 

This is a nasty thing in XSLT 1.0. In 2.0 this happens automatically. In 1.0 you need a custom function, often called blah:node-set. It is available in many XSLT toolkits (I don't know yours or PHP). If you have access to EXSLT, it contains one too. Example: http://www.ibm.com/developerworks/xml/library/x-tipxsltmp.html

Teun D