Home › Forums › General XMetaL Discussion › Count Macro › Reply To: Count Macro
Reply to: Count Macro
February 5, 2009 at 10:22 pmMag3737 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
Of course, you will need to understand XPath to be able to use this API.
So, given the following SGML (or XML)…
[code]
…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”);
ActiveDocument.Host.Alert(nodelist.length);[/code]
…the following script will return the value 3 (only those
[code]//XMetaL Script Language JScript:
var nodelist = ActiveDocument.getNodesByXPath(“//parent/coc”);
ActiveDocument.Host.Alert(nodelist.length);[/code]
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).