0

我需要这个 xml 文档中每个唯一属性的数量:

<LocValRes flag="FINAL" id="dummy">
    <Station name="Sampieri" distance="2901857" duration="3482348" externalId="008302686#80" externalStationNr="008302686" type="WGS84" x="14744601" y="36731901"/>
    <Station name="Pozzallo" distance="2903750" duration="3484620" externalId="008302642#80" externalStationNr="008302642" type="WGS84" x="14847168" y="36733609"/>
    <Station name="Scicli" distance="2907477" duration="3489092" externalId="008302695#80" externalStationNr="008302695" type="WGS84" x="14699187" y="36790088"/>
    <Station name="Ispica" distance="2909739" duration="3491806" externalId="008302562#80" externalStationNr="008302562" type="WGS84" x="14914362" y="36778043"/>
    <Station name="Rosolini" distance="2914534" duration="3497560" externalId="008302660#80" externalStationNr="008302660" type="WGS84" x="14952836" y="36815950"/>
    <Station name="Modica" distance="2915249" duration="3498418" externalId="008300462#80" externalStationNr="008300462" type="WGS84" x="14754166" y="36852950"/>
    <Station name="Donnafugata" distance="2915468" duration="3498681" externalId="008302530#80" externalStationNr="008302530" type="WGS84" x="14568817" y="36882183"/>
    <Station name="Ragusa" distance="2922026" duration="3506551" externalId="008300336#80" externalStationNr="008300336" type="WGS84" x="14725427" y="36919209"/>
    <Station name="Comiso" distance="2923096" duration="3507835" externalId="008302524#80" externalStationNr="008302524" type="WGS84" x="14600540" y="36947283"/>
    <Station name="Vittoria" distance="2923168" duration="3507921" externalId="008300491#80" externalStationNr="008300491" type="WGS84" x="14524959" y="36958762"/>
    <Station name="Noto" distance="2923895" duration="3508794" externalId="008302609#80" externalStationNr="008302609" type="WGS84" x="15074307" y="36882498"/>
    <Station name="Acate" distance="2925789" duration="3511066" externalId="008302445#80" externalStationNr="008302445" type="WGS84" x="14425430" y="36996652"/>
    <Station name="Avola" distance="2927532" duration="3513158" externalId="008302461#80" externalStationNr="008302461" type="WGS84" x="15125762" y="36907586"/>
    <Station name="Gela-Anic" distance="2929204" duration="3515164" externalId="008302743#80" externalStationNr="008302743" type="WGS84" x="14299176" y="37045013"/>
    <Station name="Licata" distance="2930810" duration="3517092" externalId="008300380#80" externalStationNr="008300380" type="WGS84" x="13938278" y="37105987"/>
    <Station name="Gela" distance="2931688" duration="3518145" externalId="008300310#80" externalStationNr="008300310" type="WGS84" x="14259255" y="37072988"/>
    <Station name="Falconara" distance="2933198" duration="3519957" externalId="008302532#80" externalStationNr="008302532" type="WGS84" x="14052468" y="37113511"/>
    <Station name="Niscemi" distance="2941720" duration="3530184" externalId="008300423#80" externalStationNr="008300423" type="WGS84" x="14403505" y="37144992"/>
    <Station name="Siracusa" distance="2947889" duration="3537586" externalId="008300338#80" externalStationNr="008300338" type="WGS84" x="15281733" y="37068907"/>
    <Station name="Campobello Ravanusa" distance="2948468" duration="3538281" externalId="008302485#80" externalStationNr="008302485" type="WGS84" x="13946350" y="37265582"/>
</LocValRes>

XPath 表达式//@*计算所有可用属性,但我只需要每个唯一属性。这对 XPath 可行吗?

4

1 回答 1

1

如果您使用的是 XPath 2.0,则可以使用distinct-values(),如下所示:

distinct-values(//@*/name())

这将返回文档中不同属性名称的列表。

如果您没有可用的 XPath 2.0(这很可能),那么我认为 XPath 不会满足您的需求;您需要使用现有的 XPath 来返回所有属性,然后使用您调用的任何语言来提取不同的名称。

于 2013-07-11T09:47:00.263 回答