Copy link to clipboard
Copied
Dear Indesign scripters,
This script is making from all the XML tags ParagraphStyles.
But it refuses to take the child elements. Do I have to use XPath expression? And how?
function main() {
var xes, n, doc, ps, xe;
if ( !app.documents.length ) return;
doc = app.activeDocument;
xes = doc.xmlElements[0].xmlElements;
n = xes.length;
while ( n-- ) {
xe = xes
; st = doc.paragraphStyles.itemByName (xe.markupTag.name );
!st.isValid && doc.paragraphStyles.add({name:xe.markupTag.name});
}
}
main();
The XML
<Workbook>
<Element_A_01>
<Element_A_01></Element_A_01>
</Element_A_01>
<Element_B_02>
<Element_B_02></Element_B_02>
</Element_B_02>
</Workbook>
Greetings from Holland
The code creates two paragraph styles namely Element_A_01 and Element_B_02. These two are created for the immediate child nodes of the Workbook node. Now it seems that you are trying to create pstyles for all the nodes in the XML, which in your case would still be these two as Element_A_01 has a child node that is also named Element_A_01 and the same is the case for Element_B_02.
If i get your point right then you need to create 4 pstyles if all the nodes have different names, but that is not wor
...Copy link to clipboard
Copied
The code creates two paragraph styles namely Element_A_01 and Element_B_02. These two are created for the immediate child nodes of the Workbook node. Now it seems that you are trying to create pstyles for all the nodes in the XML, which in your case would still be these two as Element_A_01 has a child node that is also named Element_A_01 and the same is the case for Element_B_02.
If i get your point right then you need to create 4 pstyles if all the nodes have different names, but that is not working. For this you will have to recursively traverse each node that you get from the code xes
The code be something like this
Hope this solves the issue
Copy link to clipboard
Copied
Thanks for the help,
It's a bit of an struggle for me (noob) but i'm getting there.
Now I've got it with this script, but is this the right way?
function main() {
var xes, n, doc, ps, xe;
if ( !app.documents.length ) return;
doc = app.activeDocument;
xes = doc.xmlElements[0].xmlElements;
n = xes.length;
while ( n-- ) {
xe = xes
; try
{
st = doc.paragraphStyles.itemByName (xe.markupTag.name );
!st.isValid && doc.paragraphStyles.add({name:xe.markupTag.name});
for(var i=0;i<xe.xmlElements.length;i++)
st = doc.paragraphStyles.itemByName (xe.xmlElements[0].markupTag.name );
!st.isValid && doc.paragraphStyles.add({name:xe.xmlElements[0].markupTag.name});
}
catch(e){}
}
}
main();
Greetings for Holland
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more