用于选择最后一个内部标签的 Xpath 表达式

M.E*_*.E. 4 xpath openerp

对于此 XML 摘录,我想指定“最后一个内部组”,在本例中为“报告”,但该内部区域可能有更多标签,我想要“其他信息”中的最后一个

那么我怎么能说“最后一组页面string='Other Information'”呢?

 <page string="Other Information">
    <group>
        <group string="Sales Information" name="sales_person">
            <field name="user_id"/>
            <field name="team_id" options="{'no_create': True}"/>
            <field name="client_order_ref"/>
            <field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
            <field name="project_id" attrs="{'invisible':[('state','=','sale')]}" context="{'default_partner_id':partner_invoice_id, 'default_name':name}" groups="analytic.group_analytic_accounting"/>
            <field name="related_project_id" attrs="{'readonly': ['|',('project_id','!=',False),('invoice_count','!=',0),('state','=','sale')],'invisible':[('state','!=','sale')]}" context="{'default_partner_id':partner_invoice_id, 'default_name':name}" groups="analytic.group_analytic_accounting"/>
        </group>
        <group name="sale_pay" string="Invoicing">
            <field name="fiscal_position_id" options="{'no_create': True}"/>
            <field name="invoice_status" attrs="{'invisible': [('state', 'not in', ('sale','done'))]}"/>
        </group>
        <!-- ***** THIS ONE ****** -->
        <group string="Reporting" name="technical" groups="base.group_no_one">
            <field groups="base.group_no_one" name="origin"/>
        </group>
        <!-- ***** THIS ONE ****** -->
    </group>
</page>
Run Code Online (Sandbox Code Playgroud)

Vit*_*yuk 6

选择最后一项的 xpath 是:

(somepath)[last()]
Run Code Online (Sandbox Code Playgroud)

所以@eLRuLL 的答案在一般情况下是正确的,但最好在 xpath 中保留一些结构,如果你知道你的 xml 结构 - 明确说明你需要获取标签的级别,以便在格式化刹车时 - 你会知道的:

(//page[@string="Other Information"]/group/group)[last()]
Run Code Online (Sandbox Code Playgroud)

或者至少只选择具有名称的组,而不是获取包装器组:

(//page[@string="Other Information"]//group[@name])[last()]
Run Code Online (Sandbox Code Playgroud)