tags:

views:

193

answers:

1

Hi, I have a query regarding Nant build scripts, I am fairly new to NANT build, In case I want to run a style bases on some condition in an xml file say

count(${skinFolder}/screens.temp.xml//ActionCollection/Item) > 0

is there a way to achieve this ??

thanks in advance, Sidhartha

A: 

Add the following under the project node of your NAnt script:

<script language="c#" prefix="custom">
    <code>
        <![CDATA[
        [Function("evaluate-xpath")]
        public static string EvaluateXPath(string xpath, string info)
        {
        System.Xml.XPath.XPathDocument xml = new System.Xml.XPath.XPathDocument(info);
        return xml.CreateNavigator().Evaluate(xpath).ToString();
        }
        ]]>
    </code>
</script>

Then you can use the following expression to achieve what you want:

if="${int::parse(custom::evaluate-xpath('count(//ActionCollection/Item)', path::combine(skinFolder 'screens.temp.xml'))) &gt; 0}"

Just note that if your xml file has nodes that are given a namespace, then this won't work.

Trumpi