xsl-list
[Top] [All Lists]

Re: Re: Can not convert #STRING to a NodeList! Error..

2003-11-09 11:05:26
Arun,

The Built-in template for processing elements is
(http://www.w3.org/TR/xslt#built-in-rule) :

<xsl:template match="*|/">
  <xsl:apply-templates/>
</xsl:template>

It does not know that someone is going to pass a "labelsfile"
(or any other) parameter to it. It therefore, cannot pass the "labelsfile"
(or any other) parameter as part of the xsl:apply-templates.

As result when your template matching "HEADER" is instantiated, it is not
passed such a parameter.

The simpliest way to overcome this is to override the built-in template for
elements like this:

  <xsl:template match="*">
    <xsl:param name="labelsfile"/>
    <xsl:apply-templates>
      <xsl:with-param name="labelsfile" select="$labelsfile"/>
    </xsl:apply-templates>
  </xsl:template>

Place the above template before any other template in your stylesheet. It is
almost identical to the built-in template with the exception that it defines
an xsl:parameter named "labelsfile" and passes it through to any templates
it instantiates.

This will cause the instantiation of your template matching "HEADER" with
the value for the "labelsfile" parameter as specified by you.

It is a good idea, though, not to rely on the behaviour of the built-in
templates but to be really in control and to override them for all your
elements and text nodes for which you need to perform processing different
from that of the built-in templates.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL



"arun prasath"
<arunwaits(_at_)hotmail(_dot_)com> wrote in message
news:BAY2-F135v4Cbn2ncSf0000fd90(_at_)hotmail(_dot_)com(_dot_)(_dot_)(_dot_)

Thanks Dimitre,
On seeing the process of execution,(in xmlspy), from Default Template,
control comes to my third template. I also think the same that default
template is not passing anyparameters to my third template.. I am giving
my
code: minimal possible one.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; >
    <xsl:key name="label" match="labels/label" use="@name"/>
      <!-- parameter to get the current user's language-->
      <xsl:param name="language" select="'en'"/>
<xsl:template match="/"> (first)
<xsl:choose>
   <xsl:when test="$language='en'">
    <xsl:call-template name="main">
          <xsl:with-param name="labelsfile"
select="document('English.xml')"/>
     </xsl:call-template>
   </xsl:when>
   <xsl:when test="$language='fr'">
    <xsl:call-template name="main">
       <xsl:with-param name="labelsfile" select="document('French.xml')"/>
    </xsl:call-template>
  </xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="main">(second)
  <xsl:param name="labelsfile"/>
   <xsl:for-each select="$labelsfile">
                <!-- works fine -->
<xsl:value-of select="key('label','ecollab.purchaseorder')"/>
    </xsl:for-each>
   <xsl:apply-templates>
<xsl:with-param name="labelsfile" select="$labelsfile"/>
    </xsl:apply-templates>
</xsl:template>
<xsl:template match="HEADER">(third)
    <xsl:param name="labelsfile"/>
     <xsl:for-each select="$labelsfile">
               <!-- Doesnt works -->
<xsl:value-of select="key('label','ecollab.businessfollowedby')" />
     </xsl:for-each>
</xsl:template>
<xsl:stylesheet>

sample XML
------------------
<PUR-ORD>
<DOCTYPE-ID>PO</DOCTYPE-ID>
<CONTACT>610223</CONTACT>
                <!-- value of above nodes are printed by default template
-->
<PO>
          <HEADER>header information</HEADER>

</PO>
</PUR-ORD>

What should I do to solve this problem.
thanks in advance
regards
s.arun prasath

From: "Dimitre Novatchev" <dnovatchev(_at_)yahoo(_dot_)com>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Re: Re: Can not convert #STRING to a NodeList! Error..
Date: Sun, 9 Nov 2003 16:43:19 +0100

It seems to me that your description matches completely the guess I made
in
my previous message.

If you do value your time it would be best to publish a complete (but the
minimal possible) example, including the xslt code, the source xml
document
and where you think the problem happens.

From what you have written:

      3. From this template, I am again calling child templates using
<xsl:apply-templates>
       <xsl:with-param name="labelsfile" select="$labelsfile"/>
</xsl:apply-templates>
     4. Next Default template prints the node values for some of the
xml
tags.
     5. Next when a template node is matched (third),the third
template
is
being executed, I have declared the param tag
       <xsl:param name="labelsfile"/>

Problem comes only here.. here, the variable "labelsfile" is shown as
a
String rather than a Nodelist. and its value is blank.
and when the tag <xsl:for-each select="$labelsfile"> is being
executed,
it
shows error.

it seems that the "third template" is instantiated from a "default"
template. If this is so, the default template does not use an
"xsl:with-param" when it issues "xsl:apply-templates". If this is so, no
value for any parameter is passed to the "third template" and the
xsl:param
named labelsfile does not get any value -- this causes the error message.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


_________________________________________________________________
Access Hotmail from your mobile now.
http://server1.msn.co.in/sp03/mobilesms/ Click here.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list







 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list