[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Re: msxsl:script and selectSingleNode problem
I am sorry. It was my bad. I cut my whole xsl to make it easy to post here. My actual xsl is <xsl:template match="data"> <xsl:call-template name="callInit"> <xsl:with-param name="itemNode" select="Items"/> </xsl:call-template> </xsl:template> instead of > <xsl:template match="/"> > <xsl:call-template name="callInit"> > <xsl:with-param name="itemNode" select="."/> > </xsl:call-template> > </xsl:template> and actual xml is : <data> <Items> <book>My book Title</book> <pencil>My pencil length</pencil> <pen>My pen color</pen> </items> </data> instead of > <Items> > <book>My book Title</book> > <pencil>My pencil length</pencil> > <pen>My pen color</pen> > </Items> but javascript is same > function init(itemNode) > { > if( !itemNode.length) return ""; > > var val = itemNode.item(0).selectSingleNode('book'); > > //var val = itemNode.item(0).firstChild; > > if(val!=null) > return val.text; > > return "Error"; > } sorry for not giving clear information. Thanks for your suggestion, but So I don't think I can change it to <xsl:with-param name="itemNode" select="Items/*"/> b'cos passes down all individual nodes in <Items/> So any other leads?? peace, ~Mur -----Original Message----- From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx] Sent: Friday, October 03, 2003 4:51 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: msxsl:script and selectSingleNode problem Your Javascript function is: > function init(itemNode) > { > if( !itemNode.length) return ""; > > var val = itemNode.item(0).selectSingleNode('book'); > > //var val = itemNode.item(0).firstChild; > > if(val!=null) > return val.text; > > return "Error"; > } and it is called from: > <xsl:template match="/"> > <xsl:call-template name="callInit"> > <xsl:with-param name="itemNode" select="."/> > </xsl:call-template> > </xsl:template> This statement: > var val = itemNode.item(0).selectSingleNode('book'); evaluates the XPath expression "book" and assigns the result to the variable "val". because "itemNode" is the root node (/), the XPath expression will not select anything. The only element child of the root is the "items" element. Change: > <xsl:with-param name="itemNode" select="."/> to: <xsl:with-param name="itemNode" select="*"/> Now you'll get the wanted result. ===== Cheers, Dimitre Novatchev. http://fxsl.sourceforge.net/ -- the home of FXSL "Murali Korrapati" <murali.korrapati@xxxxxxxxx> wrote in message news:D856C70D80A2394F990DCDBF52F6E6CB02F518@xxxxxxxxxxxxxxxxxxxxx > Hi, > I am getting this strange problem. Let me give my xml and script function before I explain my problem. > > my xml: > > <Items> > <book>My book Title</book> > <pencil>My pencil length</pencil> > <pen>My pen color</pen> > </items> > > > my xslt: > <xsl:stylesheet version="1.0" xmlns="" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:scrdt="urn:reval-com:scripts:datatypes"> > <xsl:template match="/"> > <xsl:call-template name="callInit"> > <xsl:with-param name="itemNode" select="."/> > </xsl:call-template> > </xsl:template> > <xsl:template name="callInit"> > <xsl:param name="itemNode"/> > <xsl:value-of select="scrdt:init($itemNode)"/> > </xsl:template> > <msxsl:script language="JScript" implements-prefix="scrdt"><![CDATA[ > function init(itemNode) > { > if( !itemNode.length) return ""; > > var val = itemNode.item(0).selectSingleNode('book'); > > //var val = itemNode.item(0).firstChild; > > if(val!=null) > return val.text; > > return "Error"; > } > ]]></msxsl:script> > > </xsl:stylesheet> > > > So my problem is, when ever I transform my xml with this template, it is printing "Error". It seems like it is not able to get to "book" node when I use selectSingleNode("book"). But variety is when ever I access it as .firstChild, it is recognizing the node and printing the correct value. > > I have no idea what is going on there. Any leads will be appreciated. > > > ~Mur > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|