Home Forums General XMetaL Discussion Code Request: Process content with XSLT Reply To: Code Request: Process content with XSLT


Reply to: Code Request: Process content with XSLT

If you just return the id value from the XSLT instead of

the task is to remove the children of

and add a new attribute with the calculated value.
I wrote the lines enclosed but I did not test. This is for reference only.
Let me know if that was of help 🙂

[code]var objNode = ActiveDocument.documentElement;
// get list of all elements to change
var nodes2change= objNode.getNodesByXPath(“address”);
var node2change;
var strAddressId;
// Work through the list if length > 0
for (var index = 0; index < nodes2change.length; index++) {
  node2change = nodes2change.item(index);
  strAddressId = your_great_xslt_function( node2change );
  // remove old stuff
  while( node2change.firstChild ) {
  // add new attribute
  node2change.setAttribute( “addressid”, strAddressId );