Majirus,
At 01:26 PM 10/15/2004, you wrote:
Hi all,
I have an result fragment named nodeset.
using xslt, Is it possible to determine an xpath expression that match
this fragment from a source document.
In general, no.
In specific cases, you could get away with
//*[.=$nodeset]
but this depends on every node in your input data having a unique (string)
value. (The string value of a node is the concatenation of all its text
node descendants.) This is not likely to be the case, though it might be
the case for your particular instance of the general question (no two books
are likely to have the same author and title, which is what the string
value in your example would amount to).
To illustrate the problem, what would you want back if
$nodeset = <author>Michael Kay</author>
and your input data had
<book ISBN= "0-7645-6909-0">
<title>XSLT programmer's reference 3e </title>
<author>Michael Kay</author>
</book>
<book ISBN= "0-7645-6909-1">
<title>XSLT programmer's Guide to British Beers and Ales</title>
<author>Michael Kay</author>
</book>
what would you want as an XPath expression?
Now, your suggestion of /descendant-or-self::book[(_at_)ISBN='0-7645-6909-0']
suggests you want to leverage the fact that you know the values of your
ISBN attributes are unique.
That's a good idea, except that Result Tree Fragments in XSLT 1.0 are not
transparent, and you have no way to reach in and grab that attribute.
Most of us would recommend using exslt:node-set() or equivalent to make the
fragment a node-set -- or to acquire that ISBN another way altogether so
you don't have to get it from a result tree. Or use //*[.=$nodeset] and
control somehow against getting false hits (say by catching as an exception
cases where more than one node comes back).
Good luck,
Wendell
for example:
$nodeset= <book ISBN= "0-7645-6909-0">
<title>XSLT programmer's reference 3e </title>
<author>Michael Kay</author>
</book>
an xpath expression is: /descendant-orself::book[(_at_)ISBN='0-7645-6909-0'].
I have the fragment from a variable ($nodeset).
I used xalan 2.1.4 as xslt processor.
all suggestions are welcome.
I thank all of you in advance.
Majirus
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================