如何使用Xpath过滤掉Wordpress插件中的日期字段?

编程入门 行业动态 更新时间:2024-10-27 21:15:34
本文介绍了如何使用Xpath过滤掉Wordpress插件中的日期字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我每天都使用WP All Import插件导入具有成千上万条记录的csv文件,但是我不需要全部,而仅需要更新的记录.csv文件中有一个最后修改时间"列,我想将其与今天的日期进行比较,并过滤掉所有不匹配的内容.

I am using the WP All Import plugin to import a csv file with thousands of records every day but I don't need all of them, only the ones that have been updated. There is a "last modified" column in the csv file which i'd like to compare to today's date and filter out anything that doesn't match.

Wp all import让您使用xpath进行此操作,但是我不知道如何在其中引用今天的日期,任何人都可以帮忙吗?

Wp all import let's you do this using xpath, but I have no idea how to reference today's date in it, can anyone help?

WP全部导入xpath screen.png

亲切的问候,

推荐答案

XPath 2.0解决方案(将其粘贴到XPath字段中)以保存当天的记录:

XPath 2.0 solution (paste it in the XPath field) to keep records of the day:

/node[@last_modified[concat(substring(.,7,4),substring(.,4,2),substring(.,1,2))=string(format-date(current-date(),"[Y][M01][D01]"))]]

我们用子字符串提取日期,将当前日期(XPath 2.0函数:不确定WP是否支持)转换为字符串,然后进行比较.我们终于把这种情况放在了方括号之间.

We extract the date with substring, convert the current date (XPath 2.0 functions : not sure WP supports it) to string and we compare them. We finally put this condition between brackets.

编辑:确定.last_modified是元素而不是属性.因此,只需从表达式中删除"@"即可:

EDIT : OK. last_modified is an element not an attribute. So just remove the "@" from the expression :

/node[last_modified[concat(substring(.,7,4),substring(.,4,2),substring(.,1,2))=string(format-date(current-date(),"[Y][M01][D01]"))]]

如果不起作用,只需在元素后添加"[1]":

If it doesn't work just add '[1]' after the element :

/node[last_modified[1][concat(substring(.,7,4),substring(.,4,2),substring(.,1,2))=string(format-date(current-date(),"[Y][M01][D01]"))]]

要完成此操作,要使用XPath 1.0保留当天的记录,您必须手动输入当天的日期(在下面的示例中为"20190820",请相应地进行更改)

EDIT 2 : To be complete, to keep records of the day with XPath 1.0, you have to enter manually the date of the day ("20190820" in the examples below, change it accordingly)

//*[last_modified[1][concat(substring(.,7,4),substring(.,4,2),substring(.,1,2))=20190820]] /node[last_modified[1][concat(substring(.,7,4),substring(.,4,2),substring(.,1,2))=20190820]]

使用XPath 2.0时,检查日期的过程应该是自动的(但似乎插件不支持它):

With XPath 2.0, the process to check the date should be automatic (but it seems the plugin doesn't support it) :

//*[last_modified[1][concat(substring(.,7,4),substring(.,4,2),substring(.,1,2))=string(format-date(current-date(),"[Y][M01][D01]"))]]

更多推荐

如何使用Xpath过滤掉Wordpress插件中的日期字段?

本文发布于:2023-07-23 19:22:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1199615.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   如何使用   插件   过滤掉   日期

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!