Skip to main content
Arun Bani
Participant
May 27, 2026 5:07 AM UTC
Question

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

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.");
}

4 replies

rob day
Community Expert
Community Expert
May 27, 2026 2:36 PM UTC

Hi ​@Arun Bani , This thread might help:

 

 

And this:

 

Translate
Legend
May 27, 2026 6:01 AM UTC

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.

Translate
Arun Bani
Arun BaniAuthor
Participant
May 27, 2026 6:36 AM UTC

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]";

Translate
Legend
May 27, 2026 10:44 AM UTC

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:

 

Translate