Questions about using JScript in XSL
I'm using Microsoft's msxsl. I have a link to another element (<A HREF=#theID>), and I need to compute the section number that contains the element with ID==theID. Once I have the target element, computing the section number is trivial: n = childNumber(ancestor("section", target)); or I guess I can use 'ancestorChildNumber' My question is, how can I find the target? In a well-formed XML document, the ID is unique, so I should be able to find it with something analogous to DHTML's document.all("theID"). Since there is no documented function that I can find, I tried a recursive search starting at the root. It contains the test if ("theID" == e.getAttribute("ID")) This causes a crash (a <script error> in the debugger) when e is an element that doesn't have an ID attribute. Doesn't the document object model spec for XML say that getAttribute returns 'null' if the attribute doesn't exist? Well, I know that the type of the target element is one of a small list of element types. So I can try to prevent the crash by testing for the element type: if (e.tagName == ... || e.tagName == ...) ... The problem is that *this* crashes when e is a text leaf, and I don't know how to test the children of the node to see which ones are text and which ones are other elements. In view of these problems, with no 'try' and 'catch' mechanism, and with no 'hasAttribute' or 'hasTagName', it seems to me that writing significant JScript scripts is doomed...at least until the object model subset is extended significantly. I hope that there is part of the spec or the documentation that I have misread or missed entirely. Please let me know if there is a way to perform this simple task in JScript. --Barry MacKichan XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format