Xpath检查值并选择子节点

时间:2014-11-07 01:58:46

标签: xml wordpress xpath

我对我的wordpress导入的后续情况感到困惑。我需要的是选择 'ResourceLink'byt xpath。该图像与'ResourceContentType'相关。那里有可能 是值01,但也是02(在节点排序中也是混合的)。我只需要'01'值,所以我需要在选择资源链接后检查这个值。

我自己写了这个xpath行;

{CollateralDetail[1]/SupportingResource[1]/ResourceVersion[1]/ResourceLink[1]}

哪个有效但是,当ResourceContentType = 02被排序为第一个时,我得到了错误的图像。我需要补充一下 我的xpath代码中的一些内容,用于检查ResourceContentType = 01。

<SupportingResource>
<ResourceContentType>01</ResourceContentType>
<ContentAudience>03</ContentAudience>
<ResourceMode>03</ResourceMode>
<ResourceVersion>
<ResourceForm>02</ResourceForm>
<ResourceVersionFeature>
<ResourceVersionFeatureType>01</ResourceVersionFeatureType>
<FeatureValue>D502</FeatureValue>
</ResourceVersionFeature>
<ResourceVersionFeature>
<ResourceVersionFeatureType>02</ResourceVersionFeatureType>
<FeatureValue>800</FeatureValue>
</ResourceVersionFeature>
<ResourceVersionFeature>
<ResourceVersionFeatureType>03</ResourceVersionFeatureType>
<FeatureValue>563</FeatureValue>
</ResourceVersionFeature>
<ResourceVersionFeature>
<ResourceVersionFeatureType>04</ResourceVersionFeatureType>
<FeatureValue>9789043026529_covr.jpg</FeatureValue>
</ResourceVersionFeature>
<ResourceVersionFeature>
<ResourceVersionFeatureType>05</ResourceVersionFeatureType>
<FeatureValue>.0572</FeatureValue>
</ResourceVersionFeature>
<ResourceLink>
url
</ResourceLink>
<ContentDate>
<ContentDateRole>01</ContentDateRole>
<Date dateformat="00">20121214</Date>
</ContentDate>
</ResourceVersion>
</SupportingResource>

1 个答案:

答案 0 :(得分:0)

您可以像这样添加ResourceContentType检查:

{CollateralDetail[1]/SupportingResource[ResourceContentType='01'][1]/ResourceVersion[1]/ResourceLink[1]}
                                       ^notice this addition^^^^