Copy link to clipboard
Copied
Hi,
How to get all xml elements in a selected paragraph to get the aid:pstyle count of a paragraph. Because a paragraph style is got overwritten of 2nd style. how to get pstyle count using xml element or paragraph?
Please refer the attached screenshot. selected paragraph xml element is 2nd li of of ul and p of ul next element. If i get accosicated xml element its returning ul element so i will get the 1st li element of ul but selected paragraph doest have that text. How to check aid pstyle of selected paragraphs text element or paragraph? selected elements of a paragraphs.
Try this code sudka_k:
//////////////////////////////////////////////////////////////////////////////////
var myDoc = app.documents[0];
var myNode = app.selection[0];
var totalAttributes = [];
var myId = [myNode];
if(myNode.constructor.name == "XMLElement"){
for(var xid = 0; xid < myNode.paragraphs[0].words.length; xid++){
var allXML = myNode.paragraphs[0].words[xid].associatedXMLElements;
for(var x = 0; x < allXML.length; x++){
var match = false;
for(var lid =
Copy link to clipboard
Copied
Hi sudha_k,
Try this code:
////////////////////////////////////////////////////////////////////////////////////
var totalAttributes = [];
getAttr(app.selection[0].associatedXMLElements);
alert(totalAttributes);
function getAttr(myNodes){
for(var i = 0; i < myNodes.length; i++){
if(myNodes[i].xmlAttributes.item("aid:pstyle").isValid){
totalAttributes.push(myNodes[i].xmlAttributes.item("aid:pstyle").value.toString());
}
if(myNodes[i].parent.constructor.name != "Document") getAttr([myNodes[i].parent]);
}
}
////////////////////////////////////////////////////////////////////////////////////
Best
Sunil
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi,
Thanks for your reply...
Please see my screenshots 1 & 2. In Document, i am selecting the element p (last element) and if i select the paragraph of the of that p and run the code it returns empty. Because of the tag structure.
Paragraphs is merged with the tag of "p" from "ul/li" and the bottom "p" tag. so if i get associatedXML element its return ul element only but selection of the paragraph text tags are one "p" tag from "ul/li" and the bottom "p".
I want to check if selected paragraph contains 2 pstyle i need to place enter mark in front the element of the 2nd pstyle element. i dont know how to check this?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Try this code:
//////////////////////////////////////////////////////////////////////////////////
var totalAttributes = [];
if(app.selection[0].constructor.name == "XMLElement"){
getAttr([app.selection[0]]);
}
if(totalAttributes.length > 1){
app.selection[0].insertTextAsContent("\r", XMLElementPosition.beforeElement);
}
//////////////////////////////////////////////////////////////////////////////////
function getAttr(myNodes){
for(var i = 0; i < myNodes.length; i++){
if(myNodes[i].xmlAttributes.item("aid:pstyle").isValid){
totalAttributes.push(myNodes[i].xmlAttributes.item("aid:pstyle").value.toString());
}
if(myNodes[i].parent.constructor.name != "Document") getAttr([myNodes[i].parent]);
}
}
//////////////////////////////////////////////////////////////////////////////////
Best
Sunil
Copy link to clipboard
Copied
Hi sudha_k,
Try this code :
//////////////////////////////////////////////////////////////////////////////////
var totalAttributes = [];
if(app.selection[0].constructor.name == "XMLElement"){
getAttr([app.selection[0]]);
}
else if(app.selection[0].constructor.name == "InsertionPoint" || app.selection[0].constructor.name =="Character" || app.selection[0].constructor.name =="Word" || app.selection[0].constructor.name == "Paragraph" || app.selection[0].constructor.name == "Text"){
getAttr(app.selection[0].associatedXMLElements);
}
alert(totalAttributes);
//////////////////////////////////////////////////////////////////////////////////
function getAttr(myNodes){
for(var i = 0; i < myNodes.length; i++){
if(myNodes[i].xmlAttributes.item("aid:pstyle").isValid){
totalAttributes.push(myNodes[i].xmlAttributes.item("aid:pstyle").value.toString());
}
if(myNodes[i].parent.constructor.name != "Document") getAttr([myNodes[i].parent]);
}
}
//////////////////////////////////////////////////////////////////////////////////
Best
Sunil
Copy link to clipboard
Copied
Hi Sunil,
The same is returning. I think that i did not say clearly my requirement.
Please see my both screenshots. As per below screenshot, xml element "p" (outside of ul element) proceeded with ul tag with two list items.
See the below screenshot, 1st paragraph is "ul/p" and 2nd paragraph is combination of ul/p and p (outside tag).
As per xml elements, its a combination of li/p and p and it contains 2 pstyle. But in paragraph text (selection) style got overrides. The originals style for p tag (selection) is "bch_tx" but its wrongly here.
I need to findout these kind of paragraphs and need to place enter infront that element (ie., element which contains 2nd pstyle) Whether using paragraph or xml element. I am trying in both way but not working.
The sample output is:
Copy link to clipboard
Copied
Try this code sudka_k:
//////////////////////////////////////////////////////////////////////////////////
var myDoc = app.documents[0];
var myNode = app.selection[0];
var totalAttributes = [];
var myId = [myNode];
if(myNode.constructor.name == "XMLElement"){
for(var xid = 0; xid < myNode.paragraphs[0].words.length; xid++){
var allXML = myNode.paragraphs[0].words[xid].associatedXMLElements;
for(var x = 0; x < allXML.length; x++){
var match = false;
for(var lid = 0; lid < myId.length; lid++){
if(myId[lid].id == allXML[x].id){
match = true;
}
}
if(!match) myId.push(allXML[x]);
}
}
getAttr(myId);
}
if(totalAttributes.length > 1){
myNode.insertTextAsContent("\r", XMLElementPosition.beforeElement);
}
//////////////////////////////////////////////////////////////////////////////////
function getAttr(myNodes){
for(var i = 0; i < myNodes.length; i++){
if(myNodes[i].xmlAttributes.item("aid:pstyle").isValid){
totalAttributes.push(myNodes[i].xmlAttributes.item("aid:pstyle").value.toString());
}
if(myNodes[i].parent.constructor.name != "Document") getAttr([myNodes[i].parent]);
}
}
//////////////////////////////////////////////////////////////////////////////////
Best
Sunil