min-non-empty-string
File: Data.xml <inventory id="inv0001" date="2008-12-19" loc="USA"> <car model="A" id="0001" quantity="1" color="navy"/> <car model="B" id="0002" quantity="1"/> <car model="B" id="0003" quantity="2"/> <car model="C" id="0004" quantity="1" color="white"/> <car model="C" id="0004" quantity="1" color="gray"/> <car model="A" id="0001" quantity="1" color="black"/> </inventory> File: Query.xquery declare namespace functx = "http://www.java2s.com"; declare function functx:min-non-empty-string ($stringSeq as xs:string*) as xs:string? { min($stringSeq[. != '']) }; (: Example call :) functx:min-non-empty-string(doc("Data.xml")//car/@model) Output: <?xml version="1.0" encoding="UTF-8"?>A