Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

XPath query

Help
Anonymous
2010-09-06
2012-10-08

  • Anonymous
    2010-09-06

    Hello,

    I'm using Saxon 9.2 and I'm wondering whether the following XPath query is
    possible - please consider the following:

    <import>
    <record ref="abc">
    <id>123</id>
    <data>Value<'data>
    </record>
    <record ref="def">
    <parent>123</parent>
    <data>Value2</data>
    </record>
    </import>

    If I evaluate a query on the <record ref="efg"> element, how can I retrieve
    the value of the ref attribute on the first <record> node? The following won't
    parse - is such a query even possible?

    /import/record@ref

    Thanks,

    JB

     
  • Michael Kay
    Michael Kay
    2010-09-06

    Please note that this forum is intended for questions and comments that are
    specific to Saxon. For general XPath programming advice, a better place is the
    xsl-list at mulberrytech.com.

    I don't really know the answer. Your English-language description of the
    problem refers to ref="efg" which isn't present in your source document. Your
    (incorrect) XPath expression can most easily be corrected to
    /import/record/@ref but that assumes you're in XSLT and current() is the the
    ref="def" element.

     

  • Anonymous
    2010-09-06

    Thanks for your response, and apologies for using the wrong forum. I did mean
    ref="def" in my description, so you are correct in assuming current is equal
    to that node.

    I note with interest that you write:

    id = current()/parent

    and not:

    id/text() = current()/parent/text()

    The former being a shorthand for the latter, I assume?

    So, is this something that is supported with Saxon's XPath implementation
    assuming I am executing an XPath query against a DOM? There's no XSLT in
    play..

    JB