我需要通过仅获取 end_date = 9999-12-31 来过滤 job_information 记录的帮助,并且如果 action 不等于“DELETE”
输入的XML如下
queryCompoundEmployeeResponse
CompoundEmployee
Person
fields...fields
fields...fields
fields...fields
Employment_Information
fields...fields
fields...fields
job_information
Action..Action
date...date
job_information
Action...Action
date...date
我在尝试这样做时陷入困境
`<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="employment_information">
<xsl:copy>
<xsl:apply-templates select="*[not(self::job_information)]"/>
<xsl:copy-of select="employment_information[job_information/end_date =
'9999-12-31']"/>
</xsl:copy>
以下是输入的XML
<?xml version="1.0" encoding="UTF-8"?>
<queryCompoundEmployeeResponse>
<CompoundEmployee>
<id></id>
<person>
<employment_information>
<action>NO CHANGE</action>
<assignment_class></assignment_class>
<job_information>
<action>NO CHANGE</action>
<end_date>9999-12-31</end_date>
<event>5</event>
</job_information>
<job_information>
<action>DELETE</action>
<end_date>1998-12-31</end_date>
<event>5</event>
</job_information>
</employment_information>
</person>
<execution_timestamp>2018-09-18T12:06:05.000Z</execution_timestamp>
<version_id></version_id>
</CompoundEmployee>
</queryCompoundEmployeeResponse>
输出应为以下 XML。应删除第二个 job_information
<?xml version="1.0" encoding="UTF-8"?>
<queryCompoundEmployeeResponse>
<CompoundEmployee>
<id></id>
<person>
<employment_information>
<action>NO CHANGE</action>
<assignment_class></assignment_class>
<job_information>
<action>NO CHANGE</action>
<end_date>9999-12-31</end_date>
<event>5</event>
</job_information>
</employment_information>
</person>
<execution_timestamp>2018-09-18T12:06:05.000Z</execution_timestamp>
<version_id></version_id>
</CompoundEmployee>
</queryCompoundEmployeeResponse>
通过仅获取 end_date = 9999-12-31 并且如果 action 不等于“DELETE”来过滤 job_information 记录
我认为可以翻译成:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="job_information[not(end_date = '9999-12-31' and action != 'DELETE')]"/>
</xsl:stylesheet>
这将删除job_information
您不想要的元素。要按照您开始的方式进行操作 - 即保留job_information
您想要的元素,它需要是:
<xsl:template match="employment_information">
<xsl:copy>
<xsl:apply-templates select="*[not(self::job_information)]"/>
<xsl:copy-of select="job_information[end_date = '9999-12-31' and action != 'DELETE']"/>
</xsl:copy>
</xsl:template>
请注意,这可能会更改元素的原始顺序,因为所需的job_information
元素将始终位于末尾。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句