Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - How to choose the first nonempty element >Thread Next - Re: How to choose the first nonempty element Re: How to choose the first nonempty elementTo: NULL Date: 4/2/2008 6:08:00 PM
khalil_mi@h... wrote:
> If I have an xml data such as the following:
>
> <csv>
>
> <line>
> <field></field>
> </line>
>
> <line>
> <field></field>
> </line>
>
> <line>
> <field>2</field>
> </line>
>
> <line>
> <field>3</field>
> </line>
>
> </csv>
>
> I need to go though all <line> elements and get the first NON-Empty
> <field>
> in the example above, it should print 2
(/csv/line/field[node()])[1]
selects the first field element that is not empty.
> I need the solution in xsl 2.0
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="/">
<xsl:value-of select="(/csv/line/field[node()])[1]"/>
</xsl:template>
</xsl:stylesheet>
That would work with XSLT 1.0 as well.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
