[xsl] ClassCastException

Subject: [xsl] ClassCastException
From: alana@xxxxxxxxxx
Date: Fri, 12 Dec 2003 11:08:46 +0530
thanks David this works but my problem still exists 

************************************************************************************
//XML
<DATA>
<component id="description_of_plates" type="question">
                <property id="label">
                    <value>Description of Plates:</value>
                </property>
                <property id="help"/>
                <property id="tooltip"/>
                <property id="format">
                    <value>textbox</value>
                </property>
                <property id="cid"></property>
                <component id="description_of_plates" type="answer">
                    <property id="ans">
                        <value></value>
                    </property>
                </component>
            </component>

<component id="description_of_seats" type="question">
                <property id="label">
                    <value>Description of Seats:</value>
                </property>
                <property id="help"/>
                <property id="tooltip"/>
                <property id="format">
                    <value>textbox</value>
                </property>
                <property id="cid"></property>
                <component id="description_of_seats" type="answer">
                    <property id="ans">
                        <value></value>
                    </property>
                </component>
  </component>

</DATA>


************************************************************************************
//XSL
<xsl:call-template name="getvalue">
              <xsl:with-param name="node">
              <xsl:call-template name="getComponentfortype">
                <xsl:with-param name="rootnode">
                   <xsl:value-of select="/DATA/component"/>
                   </xsl:with-param>
                   <xsl:with-param name="typename">answer</xsl:with-param>
             </xsl:call-template>
         </xsl:with-param>
    <xsl:with-param name="selectid">ans</xsl:with-param>
    <xsl:with-param name="attr">
          <xsl:value-of select="."/>
    </xsl:with-param>
</xsl:call-template>



<!--This would return the node's unique path in the xml -->
<xsl:template name="getComponentfortype">
         <xsl:param name="rootnode"/>
         <xsl:param name="typename"/>
         <xsl:for-each select="$rootnode//component">

            <xsl:if test="@type = $typename">
                <xsl:call-template name="node:xpath">
                    <xsl:with-param name="node" >
                        <xsl:value-of select="$rootnode/component/*[name(.)=name()]"></xsl:value-of>
                        <!--<xsl:value-of select="/DATA/component/component"></xsl:value-of>--> <!--this works -->
                    </xsl:with-param>
                 </xsl:call-template>

              </xsl:if>
        </xsl:for-each>

     </xsl:template>

<!-- this would return the value for a given property for a given component-->
<xsl:template name="getvalue" match="Component">
        <xsl:param name="node"/>
        <xsl:param name="selectid"/>
        <xsl:param name="attr"/>
        <xsl:for-each select="$node/property">
            <xsl:if test="@id = $selectid">
                <xsl:value-of select="./value"></xsl:value-of>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>

************************************************************************************

The template "getComponentfortype" would return the nodepath in String format.
I wanted to use this as the node to getvalue function to return the property value for that component.
But i get the classCastException .

I hoped to make the two templates generic.how do i correct this.
regards
Alan



-----------------------------------------------------------------------------------------------------------------------------
Alan Andrade |Off: Mastek SDF 7, SEEPZ  | email: alana@xxxxxxxxxx <mailto:alana@xxxxxxxxxx>  | Tel: 56952222 ext 1582 
-----------------------------------------------------------------------------------------------------------------------------



-----Original Message-----
From: David Carlisle [mailto:davidc@xxxxxxxxx]
Sent: Thursday, December 11, 2003 5:23 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] ClassCastException



line 17 (mentioned in teh error) is

        <xsl:for-each select="$node[1]/ancestor-or-self::*">

that expression will only be valid if the variable $node contains a node set

but you are calling it as:
      <xsl:call-template name="node:xpath">
	        <xsl:with-param name="node" >
                <xsl:value-of select="$nodew"/>
                </xsl:with-param>
	  </xsl:call-template>

so teh parameter will never be a node set it will be a result tree
fragment corresponding to a root node with a single text node child with
value teh string value of the parameter nodew.


Most of the parameters are unused so you could  change that to

<xsl:template name="getvalue2" >
        <xsl:param name="nodew"/>
      <xsl:call-template name="node:xpath">
	        <xsl:with-param name="node"select="$nodew"/>
	  </xsl:call-template>

But nodew is not a node either, depite its name. It is aanother result
tree fragment with a string value that looks like an xpath but is not a
path to the system, its just a string.


<xsl:with-param name="nodew">
          /DATA/component/<xsl:value-of select="$reqnode"/>
      </xsl:with-param>

You probably want

<xsl:with-param name="nodew" select="/DATA/component/*[name()=$reqnode]"/>

so that your parameter does contain a node set, although then this will
always be a set of element nodes, so most of the testing in the 
node:xpath template is a no-op.

David


-- 
http://www.dcarlisle.demon.co.uk/matthew

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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



MASTEK
"Making a valuable difference"
Mastek in NASSCOM's 'India Top 20' Software Service Exporters List.
In the US, we're called MAJESCO

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that of Mastek Limited, unless specifically indicated to that effect. Mastek Limited does not accept any responsibility or liability for it. This e-mail and attachments (if any) transmitted with it are confidential and/or privileged and solely for the use of the intended person or entity to which it is addressed. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. This e-mail and its attachments have been scanned for the presence of computer viruses. It is the responsibility of the recipient to run the virus check on e-mails and attachments before opening them. If you have received this e-mail in error, kindly delete this e-mail from all computers.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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


Current Thread