xml - How to count unique attributes with XPath? -


i need number of each unique attribute in xml document:

<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> 

the xpath expression //@* counts available attributes, need each unique attribute. possible xpath?

if you're using xpath 2.0, can use distinct-values(), this:

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

which return list of distinct names of attributes in document.

if don't have xpath 2.0 available (which quite likely,) don't think xpath going need; you'll need use existing xpath return attributes , use whatever language you're calling extract distinct names.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -