xml - Take attribute when available, otherwise element -


i processing xml file xslt , list of properties per item following attributes:

  • if attribute aaa set, take value of attribute
  • if attribute aaa not set, take value of element
  • from resulting set, take distinct values

here example xml

<items>     <item>         <properties>             <property aaa="">pa</property>             <property aaa="pb">pc</property>             <property aaa="pa">pa</property>         </properties>     </item>     <item>         <properties>             <property aaa="">pd</property>             <property aaa="pe">pf</property>         </properties>     </item> </items> 

now how tried achieve it:

<xsl:for-each select="/items/item">     <xsl:for-each select="distinct-values(properties/property/@aaa | properties/property)[not(. = '')]"><xsl:value-of select="."/>#</xsl:for-each> </xsl:for-each> 

the attribute aaa there, sometime empty. problem have is, if attribute , element both set, both appear in set. want attribute appear. above xml, correct solution be

pa#pb# pd#pe# 

what code gives me instead

pa#pb#pc# pd#pe#pf# 

is possible achieve that?

the fact you're using distinct-values suggests working in xslt 2.0, can combination of xpath 2.0 for , if constructs:

distinct-values(     $prop in properties/property     return if ($prop/@aaa != '') $prop/@aaa else $prop ) 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -