XSLT, parameters, value-of, and call-template

I’m running into a problem when passing a node tree to a template through a parameter and trying to use it with value-of

These are the relevant sections:

in this call the node is a tree
<xsl:call-template name=“headerSummary”>
<xsl:with-param name=“node” select="."/>
</xsl:call-template>

this is a chunk of the template
<xsl:template name=“headerSummary”>
<xsl:param name=“node”/>
<xsl:value-of select="$node/Vendor" />


where Vendor is a tag in the xml document. What happens is that I get an error complaining that can’t change #STRING into a NodeList. I looked on XSLT 2nd Edition where it is stated that the value in select could be anything also a node, so I would expect the select to give me the right value, as I would with <xsl:value-of select="./Vendor" />. So it seems to me that value-of treats $node as a string reguardless.

Any idea how I can get around that? That template is reached from different depths in the xml document, so my interest in passing a node as a parmaeter.

Thank you for suggestions

Giulia

Hi Giulia,

It should have no problem, I am doing this also. I used the xml:


ABC


XYZ



and the xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=“http://www.w3.org/1999/XSL/Transform” version=“1.0”>

<xsl:output omit-xml-declaration = “yes”/>

<xsl:template match="/">
<xsl:for-each select=“Products/Product”>
<xsl:call-template name=“headerSummary”>
<xsl:with-param name=“node” select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>

<xsl:template name=“headerSummary”>
<xsl:param name=“node”/>
<xsl:value-of select="$node/Vendor" />
</xsl:template>

</xsl:stylesheet>

I can successfully ouput ABCXYZ.

Best regards,
Lun

I can’t see anything wrong with the code snippets that you’ve posted - which usually means that the error is somewhere else. Perhaps you could post a full stylesheet and sample source document?

Michael Kay

Thanks to both, you are completely right, the problem was somewhere else.

Once I reorganized and cleaned up the stylesheet in order to send it along, I found out a number of incostintencies which I have now fixed.

Giulia