Reply to: CSS Selector last-child not workingSeptember 5, 2017 at 6:44 pm
For any selectors that are unsupported (now or into the future) or for other complex selectors that CSS just does not support in general you can use the Selection.ContainerStyle or the Range.ContainerStyle API. This will work for any element you can programmatically move a Range to in your document (ie: there is some logic you can use to uniquely identify an element). In your case running the following would likely give you what you want:
[code=Example(JScript): setting CSS through script]
//XMetaL Script Language JScript:
/*Change following XPath to suit your needs.
Hopefully it is as simple as changing the element
name from Para to yours.
Setting color:red shows how to set multiple CSS
properties on the same node. Remove that if you
don't want them red.
var xpath = “//Para[last()]”;
var nodes = ActiveDocument.getNodesByXPath(xpath);
var rng = ActiveDocument.Range;
for(var i=0; i
rng.ContainerStyle = “margin-bottom:2em; color:red”;
If that doesn't do it please provide more information on the XML structure (include a sample).
Note that in this example I use getNodesByXPath. You can use any logic to move the Range to the element you need to style. Other methods would include walking the document element by element to identify node name, content, attributes, etc. I merely use the getNodesByXPath API here because that was the simplest way to do it given the requirements.