Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 31st, 2006, 03:16 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default XPath Expression

I don't know if it is the right place for this topic but I have a question.

I am now designing an AJAX application which has a connection to an external server via SOA Protocol. It sends the envelope request and gets the XML response from the server.

I wrote this XPath expression to get the count of a node like
var test = xmldoc.selectSingleNode("//fcs:folderInfoResultSet/@count");
document.getElementById("response").innerHTML= "Folder Count = " + test.value+"<br/>";

But I also want to get the value of a subelement of this element named <highlightString>. I wrote

var test2 = xmldoc.selectSingleNode("//fcs:folderInfoResultSet/highlightString/@doc");

but it didn't work (I want to get the value of this node via Xpath like value-of select in XSL)

Can anyone help me?



Your attitude determines your altitude
__________________
Your attitude determines your altitude
 
Old July 31st, 2006, 05:14 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

A random guess, perhaps highlightString is also in the fcs namespace.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 31st, 2006, 05:22 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok I am giving the example of that SOAP Response
<GetFolderInfoResponse xmlns="urn:factiva:developer:v3_0:objects">
   <folderInfoResponse>
      <folderInfoResultSet count="2">
      <folderInfo folderType="Personal">
        <folderID>100079315</folderID>
        <folderName> AP TopHeadlines </folderName>
        <highlightString> T|trtw N|rst O|c T|asp N|rst O|c O|, T|djon N|rst O|c O|,
                          T|ntop N|ns O|c T|9000 T|dfp O|, T|osin O|, T|geg O|, T|inge
                          O|, N|de O|: O|, O|+ T|ccat N|ns O|c T|mcat N|ns O|c O|,
                          T|gspo N|ns O|c O|, T|gfas N|ns O|c O|, T|gent N|ns O|c O|,
                          T|gfod N|ns O|c O|, T|gtour N|ns O|c O|, T|godd N|ns O|c O|,
                          T|glife N|ns O|c O|, T|nrgn N|ns O|c O|, T|nrmf N|ns O|c O|,
                          T|nnam N|ns O|c O|, O|- T|article N|fmt O|c T|report N|fmt
                          O|c O|, T|file N|fmt O|c O|, T|webpage N|fmt O|c O|, O|+
                          T|en N|la O|c O|+
        </highlightString>
        <newHits>true</newHits>
        <productID>Global</productID>
        <queryHitCount>264</queryHitCount>
      </folderInfo>
      <folderInfo folderType="Personal">
        <folderID>100077055</folderID>
        <folderName> Balo-Int </folderName>
        <highlightString> T|balo N|sc O|c T|article N|fmt O|c T|report N|fmt O|c O|,
                          T|file N|fmt O|c O|, T|webpage N|fmt O|c O|, O|+
        </highlightString>
        <newHits>true</newHits>
        <productID>Global</productID>
        <queryHitCount>251</queryHitCount>
      </folderInfo>
      </folderInfoResultSet>
   </folderInfoResponse>
</GetFolderInfoResponse>

Another question:

For example I can write
var myDiv = mybody.getElementsByTagName("div")[2]; to get the 3rd div element in an array. I could get the count of that <folderInfoResponse>. How can I get the all highlightString child element values of 10 folderInfoResponse elements in AJAX?


Your attitude determines your altitude
 
Old July 31st, 2006, 05:28 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

As suspected, the highlightString is in a namespace (the same namespace as its parent) and so it needs to be prefixed in the XPath expression, just like its parent element is.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 31st, 2006, 05:30 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you mean that I should write

var test2 = xmldoc.selectSingleNode("//fcs:highlightString/@doc"); ??


Your attitude determines your altitude
 
Old July 31st, 2006, 06:03 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Write

var test2 = xmldoc.selectSingleNode("//fcs:folderInfoResultSet/fcs:highlightString/@doc");



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 31st, 2006, 06:41 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok I have written

        var xmldoc = new ActiveXObject("MSXML2.DOMDocument");
    xmldoc.loadXML(xmlHttp.responseXML.xml);
    xmldoc.setProperty("SelectionLanguage", "XPath");
    xmldoc.setProperty("SelectionNamespaces","xmlns:fc s='urn:factiva:developer:v3_0:parsers'");
    var test = xmldoc.selectSingleNode("//fcs:folderInfoResultSet/@count");
    var test2 = xmldoc.selectSingleNode("//fcs:folderInfoResultSet/fcs:highlightString/@doc");
        document.getElementById("response").innerHTML= "Folder Count = " + test.value+"<br/>";
        document.getElementById("response").innerHTML=test 2;
         alert(test2);

In document.getElementById("response").innerHTML=test 2; I receive a null object. If I add the value function like b]document.getElementById("response").innerHTML=test 2.value;[/b], I receive object required JavaScript error. What I am doing wrong?


Your attitude determines your altitude
 
Old July 31st, 2006, 07:01 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your highlightString element does not have an attribute called doc.

I'm beginning to wonder whether you need to take a step back. You seem to be writing code without thinking what it means, or without the basic knowledge to understand what it means. Why did you include "@doc" in the path expression? Were you just copying it blindly from somewhere else? Have you actually attempted to read and learn how path expressions work?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 31st, 2006, 07:12 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh s*t I have looked up the wrong SOAP XML file. There are many other type of factiva SOAP files. Ok I have corrected that sorry. Which Xpath expression can give me the value of this element? (like value-of select in XSL)

Ok I did it like that
var test2 = xmldoc.selectSingleNode("//fcs:folderInfoResultSet/fcs:highlightString");
alert(test2.nodeValue);

But it still gets the object as null. I am absolutely confused right now


Your attitude determines your altitude
 
Old July 31st, 2006, 10:25 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok I solved the problem. What I needed to write was
var test3 = xmldoc.selectSingleNode("//fcs:folderInfoResultSet/fcs:folderInfo/fcs:highlightString");
    alert(test3.text);

I have written alert(test3.value); and I didn't know that I had to write text when I try to get the value of an Element.

Now I am having just one more question. How can I get the elements and attributes in an array? I mean these Elements exit more than once that's why I have to create an array but I don't know how to.

Your attitude determines your altitude





Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath 2.0 every expression stolte XSLT 5 November 24th, 2008 03:32 PM
xpath-nested expression vinod.kumbar RSS and Atom 0 July 8th, 2008 11:36 AM
Need help with XPATH Expression benomathew XSLT 1 May 12th, 2006 04:41 AM
Need help with XPATH Expression benomathew XML 1 May 9th, 2006 03:38 PM
Logical XPath Expression rohit72 XML 0 June 23rd, 2004 11:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.