XSL/XPath - 搜索不同命名的元素(通配符?)
XSL/XPath - search differently named elements (wildcard?)
我有一个 XML 格式的地址列表,其中包含多个 'EstablishmentDetails' 使用 XSL 我希望将其转换为 geojson 文件。
<EstablishmentCollection>
<EstablishmentDetail>
<BusinessName>Company Name</BusinessName>
<BusinessType>Retail</BusinessType>
<AddressLine1>14 Somerset Place</AddressLine1>
<AddressLine2>London</AddressLine2>
<AddressLine3>...</AddressLine3>
<AddressLine4>...</AddressLine4>
<PostCode>SW11 1AP</PostCode>
</EstablishmentDetail>
</EstablishmentCollection>
我想 return 在伦敦出现的所有业务类型 'Retail'。如果伦敦在 'AddressLine2' 它可以使用这条线:
<xsl:apply-templates select="//EstablishmentDetail[BusinessType = 'Retail' and AddressLine2 = 'London']">
但是,根据地址的格式,London 可以出现在 AddressLine2、3 或 4 中(但绝不会出现在多行中)。
我如何搜索这三个节点?是否可以使用通配符?通过 Whosebug 搜索,我发现:
*[starts-with(name(), 'London')]
但我不确定如何将它与上面的工作线结合起来。
如果有帮助,我正在使用 Saxon,XPath 2。
谢谢
以下 XPath 1.0 表达式:
//EstablishmentDetail[node()[starts-with(name(), 'AddressLine') and starts-with(., 'London')] and BusinessType = 'Retail']
将 select 所有地址行以 'London' 开头且业务类型为 'Retail'.
的所有节点 EstablishmentDetail
如果你只想检查 AddressLine2
到 AddressLine4
你只需要检查这些字段,例如通过使用
//EstablishmentDetail[node()[(name() = 'AddressLine2' or name() = 'AddressLine3' or name() = 'AddressLine4') and starts-with(., 'London')] and BusinessType = 'Retail']
我不知道 XPath 2.0 是否会让生活更轻松。
您可以使用 //EstablishmentDetail[BusinessType = 'Retail' and 'London' = (AddressLine2, AddressLine3, AddressLine4)]
到 select 具有 Retail
BusinessType
的那些 EstablishmentDetail
元素,其中至少列出了一个 AddressLineX
元素是 London
.
作为替代方法,您可以使用 //EstablishmentDetail[BusinessType = 'Retail' and *[matches(local-name(), 'AddressLine[234]')] = 'London']
。
我有一个 XML 格式的地址列表,其中包含多个 'EstablishmentDetails' 使用 XSL 我希望将其转换为 geojson 文件。
<EstablishmentCollection>
<EstablishmentDetail>
<BusinessName>Company Name</BusinessName>
<BusinessType>Retail</BusinessType>
<AddressLine1>14 Somerset Place</AddressLine1>
<AddressLine2>London</AddressLine2>
<AddressLine3>...</AddressLine3>
<AddressLine4>...</AddressLine4>
<PostCode>SW11 1AP</PostCode>
</EstablishmentDetail>
</EstablishmentCollection>
我想 return 在伦敦出现的所有业务类型 'Retail'。如果伦敦在 'AddressLine2' 它可以使用这条线:
<xsl:apply-templates select="//EstablishmentDetail[BusinessType = 'Retail' and AddressLine2 = 'London']">
但是,根据地址的格式,London 可以出现在 AddressLine2、3 或 4 中(但绝不会出现在多行中)。 我如何搜索这三个节点?是否可以使用通配符?通过 Whosebug 搜索,我发现:
*[starts-with(name(), 'London')]
但我不确定如何将它与上面的工作线结合起来。
如果有帮助,我正在使用 Saxon,XPath 2。
谢谢
以下 XPath 1.0 表达式:
//EstablishmentDetail[node()[starts-with(name(), 'AddressLine') and starts-with(., 'London')] and BusinessType = 'Retail']
将 select 所有地址行以 'London' 开头且业务类型为 'Retail'.
的所有节点EstablishmentDetail
如果你只想检查 AddressLine2
到 AddressLine4
你只需要检查这些字段,例如通过使用
//EstablishmentDetail[node()[(name() = 'AddressLine2' or name() = 'AddressLine3' or name() = 'AddressLine4') and starts-with(., 'London')] and BusinessType = 'Retail']
我不知道 XPath 2.0 是否会让生活更轻松。
您可以使用 //EstablishmentDetail[BusinessType = 'Retail' and 'London' = (AddressLine2, AddressLine3, AddressLine4)]
到 select 具有 Retail
BusinessType
的那些 EstablishmentDetail
元素,其中至少列出了一个 AddressLineX
元素是 London
.
作为替代方法,您可以使用 //EstablishmentDetail[BusinessType = 'Retail' and *[matches(local-name(), 'AddressLine[234]')] = 'London']
。