How to count xml nodes using Freemarker

I looked all over the web today for a working example of how to count xml branches in the xml dom using Freemarker.  I finally came across the answer and thought I would share in case anyone else is looking for it.

Here is a sample from the XML:

  
  <asn>
    <Packages>
      <Package>
        <PackageID/>
      </Package>
      <Package>
        <PackageID/>
      </Package>
    </Packages>
  </asn>

Freemarker code:  ${asn.Packages.Package?size}

Output: 2

 

Leave a Reply