Skip to main content
Arun Bani
Participant
May 27, 2026
Question

InDesign JS: evaluateXPathExpression function not passing the colon attribute vaule issue

  • May 27, 2026
  • 2 replies
  • 48 views

Hi Guys,

 

I have tried to pass colon attribute to evaluateXPathExpression but not working please help me. 

Attributes:  @xml:id, @aid:pstyle

 

var doc = app.activeDocument;

var rootElement = doc.xmlElements[0];


var xPathQuery = "//section[@role and @xml:id and @ele-id]";
var matchedElements = rootElement.evaluateXPathExpression(xPathQuery);


if (matchedElements.length > 0) {
    
    for (var i = 0; i < matchedElements.length; i++) {
        var productNode = matchedElements[i];
        
        
        var priceNodes = productNode.evaluateXPathExpression("title[@ele-id and @aid:pstyle]");
        
        if (priceNodes.length > 0) {
            alert("Section " + (i + 1) + " Title: " + priceNodes[0].contents);
        }
    }
} else {
    alert("No Product elements found in the XML structure.");
}

2 replies

rob day
Community Expert
Community Expert
May 27, 2026

Hi ​@Arun Bani , This thread might help:

 

 

And this:

 

Legend
May 27, 2026

Try testing for name and namespace separately, e.g. @*[local-name() = 'id' and namespace-uri() = ‘http://www.w3.org/XML/1998/namespace'] . Not sure whether that uri is automatically provided as it should.

To avoid these namespace troubles, use an XSLT on import to strip them, or better use an XSLT outside, and read about shortcomings of “Sablotron” XSLT - still present in InDesign last time I checked.

Arun Bani
Arun BaniAuthor
Participant
May 27, 2026

I tired namespace not working, could you please provide the correct code please

var xPathQuery = "//section[@role and @*[local-name()='id' and namespace-uri()=‘http://www.w3.org/XML/1998/namespace'] and @ele-id]";

Legend
May 27, 2026

Sorry, can’t do that experimentation for you, it would be a too big time sink.

Maybe you can find some ideas in the old, similar thread: