Qweb Xpath of child node in odoo / openERP?

江枫思渺然 提交于 2019-12-13 15:42:39

问题


Here i want insert a LI item inside existing UL

I tried this,

XML

<ul id="top_menu">
    <li><a>1</a></li>
    <li><a>2</a></li>
    <li><a>3</a></li>
</ul>

XPATH

  <xpath expr="//ul[@id='top_menu']/li[1]" position="after">
     <li><a>100</a></li>
  </xpath>

I got my new item "100" at last item of <ul>. but i need it in after 1st item. Thanks in advance.


回答1:


Sometime in tricky solution, we need to override/replace base id and than rearrange it based on our requirement.

try with this code:

Replace your code

<xpath expr="//ul[@id='top_menu']/li[1]" position="after">
    <li><a>100</a></li>
</xpath>

with

<xpath expr="//ul[@id='top_menu']" position="replace">
    <ul id="top_menu">
        <li><a>1</a></li>
        <li><a>100</a></li>
        <li><a>2</a></li>
        <li><a>3</a></li>
    </ul>
</xpath>


来源:https://stackoverflow.com/questions/35124359/qweb-xpath-of-child-node-in-odoo-openerp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!