Lawrence,

My Xml-Document looks somehow like this:
<SAMPLE-FRAG>
<ELEMENTS>
 <FRAMES>
  <FRAME>
   <SIGNAL-INSTANCE>
    <SIGNAL-REF idRef="sig1"/>
   </SIGNAL-INSTANCE>
   <SIGNAL-INSTANCE>
    <SIGNAL-REF idRef="sig2"/>
   </SIGNAL-INSTANCE>
  </FRAME>
  <FRAME>
   <SIGNAL-INSTANCE>
    <SIGNAL-REF idRef="sig2"/>
   </SIGNAL-INSTANCE>
   <SIGNAL-INSTANCE>
    <SIGNAL-REF idRef="sig3"/>
   </SIGNAL-INSTANCE>
   <SIGNAL-INSTANCE>
    <SIGNAL-REF idRef="sig4"/>
   </SIGNAL-INSTANCE>
  </FRAME>
 </FRAMES>
 <FUNCTIONS>
  <FUNCTION>
   <INPUT-PORT>
    <SIGNAL-REF idRef="sig1"/>
   </INPUT-PORT>
   <OUTPUT-PORT>
    <SIGNAL-REF idRef="sig2"/>
   </OUTPUT-PORT>
   <OUTPUT-PORT>
    <SIGNAL-REF idRef="sig4"/>
   </OUTPUT-PORT>
  </FUNCTION>
  <FUNCTION>
   <INPUT-PORT>
    <SIGNAL-REF idRef="sig2"/>
   </INPUT-PORT>
   <INPUT-PORT>
    <SIGNAL-REF idRef="sig3"/>
   </INPUT-PORT>
   <OUTPUT-PORT>
    <SIGNAL-REF idRef="sig4"/>
   </OUTPUT-PORT>
  </FUNCTION>
 </FUNCTIONS>
 <SIGNALS>
  <SIGNAL id="sig1"/>
  <SIGNAL id="sig2"/>
  <SIGNAL id="sig3"/>
  <SIGNAL id="sig4"/>
 </SIGNALS>
</ELEMENTS>
</SAMPLE-FRAG>

I'm generally interested in resolving relations between
the tree containers FUNCTIONS, FRAMES and SIGNALS.

For example:
        Which FUNCTION- rsp. FRAME-Nodes refer to given Signal?
        Which SIGNAL-Nodes are refererd by a given FRAME rsp. FUNCTION?


By the way I've  checked my classpath:
It contains saxon8.jar but not saxon8-dom.jar.

Thanks and Cheers,

Siggi





Lawrence  Jones  wrote:

I too have had a go at this, but I too am not an XPath expert.
First  of  all  make  sure  you  have  _all  of_  saxon8.jar  and  
saxon8-dom.jar
and  xbean_xpath.jar  (in  addition  to  the  normal  xbean.jar  and  the  JSR  
173
jar)  on  your  classpath.  Not  having  saxon8-dom.jar  can  cause  strange
errors.  Not  having  xbean_xpath.jar  just  means  that  no  XPath  will  work.

Other  than  that  I  think  it  might  just  be  that  we're  not  passing  in 
 the
right  XPath.  Siegfried,  can  you  attach  an  example  XML  instance  
document
for  which  you  are  expecting  this  to  work?

Here's  the  one  I  tried:

<elem1  xmlns=\"http://laj.org/test\";  >
 <elem11  id=\"123\"  >text11</elem11>
 <elem21  id=\"456\"  >text11</elem21>
 <elem12  idRef=\"123\"  />
 <elem13  idRef=\"456\"  />
 <elem14  idRef=\"123\"  />
 <elem15  idRef=\"456\"  />
 <elem16  idRef=\"123\"  />
 <elem17  idRef=\"789\"  />
</elem1>

And  here  are  the  issues  I  see.

1.  The  element  on  which  you  perform  the  selectPath()  call  seems  to
represent  the  root  as  far  as  the  call  to  selectPath()  is  concerned.  
So
if  e.g.  you  passed  in  only  the  XmlObject  for  <elem11>  above  you  
should
not  expect  any  of  the  other  elements  to  be  returned  regardless  of  
the
XPath passed in.
2.  But  it  is  likely  that  the  elements  with  idRef  in  them  are  _not_
children  of  the  element  with  id  in  them.  Rather  it  is  likely  that  
they
are  all  members  of  some  larger  document  element  such  as  <elem1>  
above.
So  to  get  the  selectPath()  to  even  consider  them  you  would  need  to  
pass
in  the  XmlObject  for  <elem1>  (or  at  least  some  element  that  is  a  
root  to
all  of  the  results  you  expect).

3.  But  then  the  path  to  the  id  attribute  is  no  longer  $this/@id  as 
 that
would  only  match  the  _root_  element  (<elem1>  in  this  case)  having  an 
 id
attribute.  Exactly  what  you  need  to  pass  in  depends  on  what  you  
want  to
do  -  if  you  want  to  find  all  idRefs  that  match  _any_  id  attribute
anywhere  in  the  document  then  you  probably  want  $this//@id  instead.

4.  I  tried  the  XPath  //[EMAIL PROTECTED]//@id]  on  the  complete  document
above  (i.e.  I  executed  selectPath()  on  the  XmlObject  representing
<elem1>)  and  printed  out  the  list  of  XmlObjects  returned  from
selectPath().  I  got:

Number  of  results  =  5
results[0]  =  <xml-fragment  idRef="123"/>
results[1]  =  <xml-fragment  idRef="456"/>
results[2]  =  <xml-fragment  idRef="123"/>
results[3]  =  <xml-fragment  idRef="456"/>
results[4]  =  <xml-fragment  idRef="123"/>

which  is  what  I'd  expect  i.e.  I  get  all  the  nodes  with  an  idRef  
that
matches  any  id  attribute  somewhere  else  in  the  document  (and  I  don't 
 get
those  that  do  not  match).  Not  sure  why  they  are  xml-fragment's  rather
than  proper  individual  elements  with  proper  QNames  but  that's  a
different  issue.

5.  Note  that  replacing  '$this'  with  '.'  (i.e.  XPath  =  //[EMAIL 
PROTECTED]//@id)
gave  me  an  empty  result  set.  My  guess  is  that  '.'  is  evaluated
dynamically  (i.e.  it  means  the  current  node  that  the  query  has  
evaluated
to)  compared  to  $this  which  is  bound  statically  at  the  beginning  to  
the
root  node  that  you  pass  in.  (With  the  '.'  version  of  the  XPath  I  
think
you  are  looking  for  a  node  which  has  both  an  id  and  an  idRef  
attribute
where  the  values  are  the  same  -  which  is  a  slightly  different  
query.)

I  haven't  tried  this  exhaustively  -  I'm  not  sure  what  would  happen  
if
some  of  the  id  or  idRef  attributes  were  on  elements  at  deeper  
levels.
But  anyway  I  hope  that  helps  get  started.

Cheers,

Lawrence

-----Original  Message-----
From:  Radu  Preotiuc-Pietro
Sent:  Thursday,  March  30,  2006  1:56  PM
To:  user@xmlbeans.apache.org
Subject:  RE:  selectPath  with  FilterExpression  using  $this

I  was  curious  to  try  this  myself  with  the  new  Saxon  8.6  integration
(available  from  the  SVN  head  only,  for  the  moment)  and  what  I  found 
 is
that  the  path  you  are  suggesting  ("//[EMAIL PROTECTED]/@id]")  works  (no
exception)  but  for  some  reason  doesn't  return  anything.  On  the  other
hand,  "//[EMAIL PROTECTED]'1'"  returns  the  expected  result,  so  on  one  
hand  I
am
wondering  if  this  is  maybe  a  bug  in  the  free  version  of  Saxon  and  
on
the
other  you  can  use  this  to  workaround  the  problem  by  doing
.selectPath("//[EMAIL PROTECTED]'"  +  node.getId()  +  "'").

If  anyone  else  has  other  insights  into  why  the  original  path  does  
not
work  (with  more  Xpath/Saxon  knowledge),  I'd  also  be  interested  to
know.
Thanks,
Radu

-----Original  Message-----
From:  Cezar  Andrei
Sent:  Wednesday,  March  29,  2006  3:30  PM
To:  user@xmlbeans.apache.org
Subject:  RE:  selectPath  with  FilterExpression  using  $this

Hi  Siegfried,

I'm  not  an  expert  in  xpath/xquery  but  I'm  pretty  sure  that  $this
doesn't
represent  the  internal  current  node  that  is  processed  by  the  engine.

So  you'll  probably  want  to  rewrite  the  expression  to  something  like
this:
xo.selectPath(".//[EMAIL PROTECTED]//@id]");

As  for  $this,  it's  just  a  variable  that  is  bound  to  the  XmlObject  
that
you  are  calling  the  selectPath  method  from.  The  '$this'  construction
is
not  in  the  latest  XPath/Xquery  spec  so  it  was  deprecated,  instead  "."
should  be  used.

The  current  XmlObject  can  be  bound  to  any  user  specified  variable  
name
as  in  the  following  example:

     XmlOptions  options  =  new  XmlOptions();
     options.setXqueryCurrentNodeVar("myVariable");
     XmlObject[]  res  =  xo.selectPath("declare  variable  $myVariable
external;  $myVariable//el1",  options);

Which  is  equivalent  to:

     XmlObject[]  res  =  xo.selectPath(".//el1",  options);

And  to  the  following  (since  in  the  context  of  the  xpath  engine  the  
xo
is
considered  the  root):

     XmlObject[]  res  =  xo.selectPath("//el1",  options);

Since  we  don't  control  Saxon,  we  can't  promise  that  expressions
confirming  to  the  spec  will  work.  We  can  only  work  on  making  sure  
we
make  the  right  calls  into  Saxon.

Cezar


-----Original  Message-----
From:  Siegfried  Baiz  [mailto:[EMAIL PROTECTED]
Sent:  Tuesday,  March  14,  2006  12:11  PM
To:  user@xmlbeans.apache.org
Subject:  selectPath  with  FilterExpression  using  $this

Hello,

for  a  given  XmlObject  xo  with  an  ID-Attribute  'id',  I've  tried  to
launch  the  following  xpath-expression:

   xo.selectPath("//[EMAIL PROTECTED]/@id]")

in  order  to  get  all  nodes  (with  idRef-Attribute)  refering  to  my  node
xo.
Unfortunatlly  this  expression  seems  not  to  work.  I  always  get  an
java.lang.ArrayIndexOutOfBoundsException  from  the  underlying

net.sf.saxon.expr.XPathContextMajor.setLocalVariable(XPathContextMajor.j
av
a:213)

At

http://xmlbeans.apache.org/docs/2.0.0/guide/conSelectingXMLwithXQueryPat
hX
Path.html
I  found  the  following  notice:
 "Notice  in  the  query  expression  that  the  variable  $this
represents
 the  current  context  node  (the  XmlObject  that  you  are  querying
from).
 In  this  example  you  are  querying  from  the  document  level
XmlObject."
After  reading  that  sentence  I've  been  thinking,  that  $this  is
somehow
similar  to  "curent()"  in  XSLT,  but  maybe  a  got  the  meaning  wrong.

Does  anyone  know  whats  the  problem  here  rsp.
is  there  a  better  way  to  accomplish  the  same  thing?

Thanks  a  lot,

Siggi




---------------------------------------------------------------------
To  unsubscribe,  e-mail:  [EMAIL PROTECTED]
For  additional  commands,  e-mail:  [EMAIL PROTECTED]
_______________________________________________________________________
Notice:  This  email  message,  together  with  any  attachments,  may
contain
information  of  BEA  Systems,  Inc.,  its  subsidiaries  and
affiliated
entities,  that  may  be  confidential,  proprietary,  copyrighted
and/or
legally  privileged,  and  is  intended  solely  for  the  use  of  the
individual
or  entity  named  in  this  message.  If  you  are  not  the  intended
recipient,
and  have  received  this  message  in  error,  please  immediately  return
this
by  email  and  then  delete  it.

---------------------------------------------------------------------
To  unsubscribe,  e-mail:  [EMAIL PROTECTED]
For  additional  commands,  e-mail:  [EMAIL PROTECTED]


_______________________________________________________________________
Notice:  This  email  message,  together  with  any  attachments,  may
contain
information  of  BEA  Systems,  Inc.,  its  subsidiaries  and
affiliated
entities,  that  may  be  confidential,  proprietary,  copyrighted
and/or
legally  privileged,  and  is  intended  solely  for  the  use  of  the
individual
or  entity  named  in  this  message.  If  you  are  not  the  intended
recipient,
and  have  received  this  message  in  error,  please  immediately  return
this
by  email  and  then  delete  it.

---------------------------------------------------------------------
To  unsubscribe,  e-mail:  [EMAIL PROTECTED]
For  additional  commands,  e-mail:  [EMAIL PROTECTED]

_______________________________________________________________________
Notice:  This  email  message,  together  with  any  attachments,  may  contain
information  of  BEA  Systems,  Inc.,  its  subsidiaries  and  affiliated
entities,  that  may  be  confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to