473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

pass variable to xpath?

I am trying to find out if there is a way to pass a variable $fquote to
xpath ...[qtnum="help"]
$fquote would be derived from a form. Any help may save what is left of my
hair!!

<?php
$s = simplexml_load_file('fishquotes.xml');
$fquote = "245";
$findquote = $s->xpath('/fishingquotes/quote[qtnum="260"]');
....?>

<?xml version="1.0"?>
<fishingquotes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<quote>
<qtnum>101</qtnum>
<title>Small Fish</title>
<copy>Govern a family as you would</copy>
<copy> cook a small fish; </copy>
<copy>very gently.</copy>
<author> Chinese Proverb</author>
<comment>None</comment>
</quote>
<!--and 450 more quotes-->
</fishingquotes>
--
Tony Bishop
www.bishfish.co.nz
New Zealand
--
Tony Bishop
www.bishfish.co.nz
New Zealand
Jul 17 '05 #1
2 3067
Bishfish <fi**********@hotmail.com> wrote:
I am trying to find out if there is a way to pass a variable $fquote to
xpath ...[qtnum="help"]
$fquote would be derived from a form. Any help may save what is left of my
hair!!

<?php
$s = simplexml_load_file('fishquotes.xml');
$fquote = "245";
$findquote = $s->xpath('/fishingquotes/quote[qtnum="260"]');
...?>


Looks like you are asking a very basic string question. Time to RTFM?
Hard to tell since you didn't ask a specific question. What is supposted
to happen with $fquote? Should it be used instead of the hardcoded 260
value?

Anyway:
http://www.php.net/manual/en/language.types.string.php

See the difference between single quoted strings and double quoted:

<?php
$foo="bar";
echo "foo='$foo'\n";
echo 'foo="$foo"\n';
echo "foo=\"$foo\"\n";
echo 'foo="'.$foo.'"\n';
echo "etc.\n";
?>

So maybe you are looking for:
....xpath("/fishingquotes/quote[qtnum='$fquote']");

In that case $fquote has to be "XML escaped" (see htmlspecialchars()).

Jul 17 '05 #2
Thanks Daniel - you answered the question I did not ask - something about
wood and trees springs to mind :-)
--
Tony Bishop
www.bishfish.co.nz
New Zealand
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Sherman Willden | last post by:
I am trying to use Perl's XML::Twig to modify a version number in an XML document. At the very end of this posting is an excerpt from the xml document. Just before the xml excerpt is the Perl code...
4
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...
3
by: axial | last post by:
Is there a way to define a variable by resolving other variables? I'm trying to build an "uber-variable" from user-selected components. I have control over the XML and can change it as needed. ...
6
by: david | last post by:
For example, I can call <xsl:value-of select="concat('name','(',value,')')"/>, is there anyway I can pass the expression concat('name','(',value,')') as a variable from outside the template? ...
2
by: Alistair Bayley | last post by:
(.Net framework version 1.1.4322) The following XSL test case is rejected by System.Xml.Xsl.XslTransform, with an XsltException: "($dummy)+0 is an invalid XPath expression." If you remove the...
0
by: KathyB | last post by:
Hi, I'm using the following xmlDocument and xpath to load a file using a variable. I've tried several renditions of the xpath using the variable but without success (error: object variable not...
2
by: jobooker | last post by:
I'm having issues sorting. The short description is, how do I set the select attribute of xsl:sort to be the value of an xsl:variable? The longer description follows: What I want to do is to be...
2
by: 张韡武 | last post by:
We have preffered language set as variable in xslt: <xsl:variable name="preferred_language"> zh </xsl:variable> Data: <name xml:lang="de">Raw Materials (Mining incl.)</name> <name...
2
by: =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?= | last post by:
Hello guys, I was wondering if it was possible to reference a boolean predicate in a variable. Basically I want to do with the boolean predicate what you would do with any other variable; I want...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.