Hi all,
I am new to XPath. I have a doubt in it.
My xml is like this:
<UserInfo>
<Contacts>
<Name>Chris Bob</Name>
</Contacts>
<Contacts>
<Name>Mike Chris</Name>
</Contacts>
<Contacts>
<Name>Chris</Name>
</Contacts>
<Contacts>
<Name>Chrisine</Name>
</Contacts>
<Contacts>
<Name>Kiran Kumar</Name>
</Contacts>
<Contacts>
<Name>Kumar</Name>
</Contacts>
</UserInfo>
So, i want to search for all names with the value in enter in html text
box.
If i enter Kumar then the last two nodes should come as it has kumar in
it. Similarly if i enter Chris then first three nodes should display,
but the fourth one should not come.
Is this possible. Please help me on how to do it.
--Phani 10 5847
Phani wrote: I am new to XPath. I have a doubt in it.
My xml is like this:
<UserInfo> <Contacts> <Name>Chris Bob</Name> </Contacts> <Contacts> <Name>Mike Chris</Name> </Contacts> <Contacts> <Name>Chris</Name> </Contacts> <Contacts> <Name>Chrisine</Name> </Contacts> <Contacts> <Name>Kiran Kumar</Name> </Contacts> <Contacts> <Name>Kumar</Name> </Contacts> </UserInfo>
So, i want to search for all names with the value in enter in html text box.
If i enter Kumar then the last two nodes should come as it has kumar in it. Similarly if i enter Chris then first three nodes should display, but the fourth one should not come.
If you use the XPath
/UserInfo/Contacts/Name[contains(., 'Kumar')]
then all <Name> elements that contain the string 'Kumar' are found.
--
Martin Honnen http://JavaScript.FAQTs.com/
> Hi all, I am new to XPath. I have a doubt in it.
My xml is like this:
<UserInfo> <Contacts> <Name>Chris Bob</Name> </Contacts> <Contacts> <Name>Mike Chris</Name> </Contacts> <Contacts> <Name>Chris</Name> </Contacts> <Contacts> <Name>Chrisine</Name> </Contacts> <Contacts> <Name>Kiran Kumar</Name> </Contacts> <Contacts> <Name>Kumar</Name> </Contacts> </UserInfo>
So, i want to search for all names with the value in enter in html text box.
If i enter Kumar then the last two nodes should come as it has kumar in it. Similarly if i enter Chris then first three nodes should display, but the fourth one should not come. Is this possible. Please help me on how to do it.
Hi,
This is a regular expression problem, regexes are not defined in XSLT1.0, but will be in XSLT2.0
Meanwhile you can use extension, or work around it (in a quite ugly way):
<xsl:apply-templates select="Contacts[contains(concat(' ',Name,' '),concat(' ',$name,' '))]"/>
Or, alternatively, if you can, you should extend the XML structure: split the name node in a 'name' and 'surname' node.
regards,
--
Joris Gillis ( http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Hi Martin,
I have tried your suggestion and it didn't worked out. It is popping up
an error message saying :
Unknown method.
/UserInfo/Contacts/Name[-->contains(.<--,"Apple")]
The following is the code which i have written:
<html>
<head>
<style type="text/css">
Body {font-family:Arial; }
th {font-size:0.8em;}
td {font-size:0.8em;}
p {font-size:0.8em;}
</style>
</head>
<body>
<xml id="UserInfo" src="test.xml"></xml>
<p>Enter Name: <input type='text' name=col_no style='border:1px solid
#d2d2d2'>
<input type=button name='Search' value='Search Now' style='border:1px
solid black;height=20px'onClick='javascript:var sepvar
= col_no.value;
SetAndFilter(UserInfo,DataExtractLower,"UserInfo/Contacts/Name[contains(.,\"Apple\")]")'></p>
<xml id="DataExtractLower"></xml>
<table datasrc="#DataExtractLower" width=100% border=0>
<thead bgcolor="#d2d2d2">
<th>Name</th>
<th>Location</th>
<th>Phone</th>
<th>Extn</th>
<th>Title</th>
<th>Department</th>
</thead>
<tr bgcolor="#e2e2e2">
<td width="15%"><span datafld="Name"></span></td>
<td width="15%"><span datafld="Location"></span></td>
<td width="15%"><span datafld="Phone"></span></td>
<td width="15%"><span datafld="Extn"></span></td>
<td width="20%"><span datafld="Desig"></span></td>
<td width="20%"><span datafld="DeptCC"></span></td>
</tr>
</table>
<script language=javascript>
function SetAndFilter (sourceXML, destXML, XPathFormula) {
alert(XPathFormula);
sourceXML.setProperty("SelectionLanguage", "XPath");
var dummy = destXML.XMLDocument.loadXML(sourceXML.xml);
vNodesToRemove = destXML.selectNodes(XPathFormula) ;
vNodesToRemove.removeAll();
}
</script>
</body>
</html>
So, whatever the user types in should check for the initial characters
of both firstname and last name.
If a user enters "cla" then it should bring back "Michael clark" as
well as "clark michael"
Hope my question is understandable. I learnt a way to program to
display xml like html tables using data islands...
--Phani
Phani wrote: I have tried your suggestion and it didn't worked out. It is popping up an error message saying :
Unknown method. /UserInfo/Contacts/Name[-->contains(.<--,"Apple")]
Are you using IE 6? Only IE 6 comes with MSXML 3 which supports XPath
1.0, earlier versions of IE come with an MSXML version that doesn't
support XPath 1.0. So you either need to install IE 6 or you need to
install MSXML 3 in so called replace mode.
<script language=javascript> function SetAndFilter (sourceXML, destXML, XPathFormula) { alert(XPathFormula); sourceXML.setProperty("SelectionLanguage", "XPath"); var dummy = destXML.XMLDocument.loadXML(sourceXML.xml); vNodesToRemove = destXML.selectNodes(XPathFormula) ;
--
Martin Honnen http://JavaScript.FAQTs.com/
I have installed IE6 installed Martin.
Can you tell me on any other ways to do this type of things.
I wanted to load all xml in single shot(when page loads) and then use
the xml (or data islands) to search /filter.
Please let me know on this...
--Phani.
Phani wrote: I have installed IE6
Looking at your code again I think the problem is here:
sourceXML.setProperty("SelectionLanguage", "XPath");
var dummy = destXML.XMLDocument.loadXML(sourceXML.xml);
vNodesToRemove = destXML.selectNodes(XPathFormula) ;
You need to set the SelectionLanguage on destXML e.g.
destXML.setProperty("SelectionLanuage", "XPath")
--
Martin Honnen http://JavaScript.FAQTs.com/
Yep Martin, i have tried it and this time i didn't got any error.
The javascript written in the code is wrong. It is working only if the
xpath expression contains "!".
like if name!="Apple" then destXML contains only the documents which
have Apple in them.
I need to change it. Can you help me on this. I think vNodesToRemove is
where the problem is .
Can we use "not" expression in XPATH.
--Phani
On Thu, 09 Dec 2004 12:30:48 GMT, "Joris Gillis" <ro**@pandora.be> wrote: Ceterum censeo XML omnibus esse utendum
What's the latin translate to? 'XML is for us all to enjoy'?
Thanks
Jeff Kish
>> Ceterum censeo XML omnibus esse utendum What's the latin translate to? 'XML is for us all to enjoy'?
:-) that would have been a nice slogan too...
It means: "Furthermore, I'm of the opinion that XML should be used by everyone/for everything/to every purpose"
At least that's what the translation ought to be. I'm not entirely sure if that's the precise translation, but grammatically it is correct or at least should be since I'm in the 6th Latin class.
I'd also like to invent a slogan with W3C in it, but I've not enough inspiration...
--
Joris Gillis ( http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: bdinmstig |
last post by:
I refined my attempt a little further, and the following code does
seem to work, however it has 2 major problems:
1. Very limited support for XPath features
Basic paths are supported for...
|
by: gael.pegliasco |
last post by:
Hi,
How are you dear and nice helper :) ?
I'm trying to test xpath with this simple program :
import xml.dom.minidom
from xml.xpath.Context import Context
import xml.xpath
|
by: Son KwonNam |
last post by:
In XSLT, is this possible to get value from xml using XPath
which is in XSLT variable?
I mean XPath strings can be dynamic while XSL Transforming.
If possible, How??
Because I'm not a...
|
by: laks |
last post by:
Hi
I have the following xsl stmt.
<xsl:for-each select="JOB_POSTINGS/JOB_POSTING
\">
<xsl:sort select="JOB_TITLE" order="ascending"/>
This works fine when I use it.
But when using multiple...
|
by: jacksu |
last post by:
I have a simple program to run xpath with xerces 1_2_7
XPathFactory factory = XPathFactory.newInstance();
XPath xPath = factory.newXPath();
XPathExpression xp = xPath.compile(strXpr);...
|
by: David Thielen |
last post by:
Hi;
I am sure I am missing something here but I cannot figure it out. Below I
have a program and I cannot figure out why the xpath selects that throw an
exception fail. From what I know they...
|
by: Gnic |
last post by:
Hi ,
I have an XmlDocument instance, I want to find a node in the xml, but I
don't know it's path until runtime, for example
<aaa>
<bbb name="x"/>
<aaa attr="y">
<ccc>sometext</ccc>
</aaa>
|
by: werD |
last post by:
Hello
I have an xml document that im currently using a forward only .net
repeater on and using some xpath queries to display the data
The xml is quite simple
<?xml version="1.0"...
|
by: Jason Mobarak |
last post by:
Hello --
I'm attempting to get a handle on how to do xpath queries with
System.Xml -- so far the biggest hurdle has been how to deal with a
default namespace. If I use the test xml:
<?xml...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
header("Location:".$urlback);
Is this the right layout the...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
| |