如何使用Xpath过滤掉Wordpress插件中的日期字段? [英] How to use Xpath to filter out date field in Wordpress plugin?

查看:66
本文介绍了如何使用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插件中的日期字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆