Home Forums General XMetaL Discussion Count Macro Reply To: Count Macro

Derek Read

Reply to: Count Macro

Mag3737 has given you the exact answer for your very specific issue.

But…just in case you need to take this a little further at some point, XMetaL Author and XMAX also have an API called getNodesByXPath() which lets you use an XPath expression to return a list of nodes like getElementsByTagName() does. It would not give you any additional benefits in your very specific case. However, if for example you needed to know how many are contained within another specific element and only that other element (assuming it might also appear elsewhere) you could use getNodesByXPath() instead.

Of course, you will need to understand XPath to be able to use this API.

So, given the following SGML (or XML)…

…the following script will return the value 5, which is the same result Mag3737's script will give:
[code]//XMetaL Script Language JScript:
var nodelist = ActiveDocument.getNodesByXPath(“//coc”);

…the following script will return the value 3 (only those inside ):
[code]//XMetaL Script Language JScript:
var nodelist = ActiveDocument.getNodesByXPath(“//parent/coc”);

Also, keep in mind that both of these APIs are case-sensitive. For XML people that should be a no-brainer, but I could see some SGML people not catching that (depending on your SGML Declaration file settings).