Apply a paragraph style for the XML elements that have a specific attribute

(1) I am an almost complete noob when it comes to XML

(2) I have a XML with a ssstructure like this:

<chapter>
     <paragraph> bla bla </paragraph>
     <paragraph> bla bla </paragraph>
     <list type="disk">
          <listitem>
               <paragraph> bla bla </paragraph>
               <paragraph> bla bla </paragraph>
          </listitem>
          <listitem>
               <paragraph> bla bla </paragraph>
               <paragraph> bla bla </paragraph>
          </listitem>
          <listitem>
               <paragraph> bla bla </paragraph>
               <paragraph> bla bla </paragraph>
          </listitem>
     </list>

     <list type="square">
          <listitem>
               <paragraph> bla bla </paragraph>
               <paragraph> bla bla </paragraph>
          </listitem>
          <listitem>
               <paragraph> bla bla </paragraph>
               <paragraph> bla bla </paragraph>
          </listitem>
          <listitem>
               <paragraph> bla bla </paragraph>
               <paragraph> bla bla </paragraph>
          </listitem>
     </list>
</chapter>

Is there an easyer (except the xmlElements) way to find all the lists and apply the appropriate paragraph style (I have a definition of 'list_with_disk' and a 'list_with_square' one)?

Hi Vamitul,

Please try the JS code below.

var myDoc = app.activeDocument;
//____________________ disk bullet style apply
try{
    var rootElement = myDoc.xmlElements.item(0);
    var linkElementList = rootElement.evaluateXPathExpression("//list[@type='disk']//paragraph");
    for(i=linkElementList.length-1; i>=0; i--){
        var myAttribute = linkElementList[i];
        myAttribute.xmlContent.appliedParagraphStyle = myDoc.paragraphStyles.itemByName("Disk");
        }
    }catch(e){}
//_______________________________________________________________________________

//____________________ Squar bullet style apply
try{
    var rootElement = myDoc.xmlElements.item(0);
    var linkElementList = rootElement.evaluateXPathExpression("//list[@type='square']//paragraph");
    for(i=linkElementList.length-1; i>=0; i--){
        var myAttribute = linkElementList[i];
        myAttribute.xmlContent.appliedParagraphStyle = myDoc.paragraphStyles.itemByName("Square");
        }
    }catch(e){}
//_______________________________________________________________________________

THX,

csm_phil

Tags: InDesign

Similar Questions

  • Apply a paragraph style to the first cell in the first row of a table

    I want to apply a paragraph style to the first cell in the first row of a table.

    I use JavaScript with ID CS 5.

    Thank you.

    . aragraphStyles.itemByName ("NameOfStyle") .p appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.itemByName ("NameOfGroup")

  • Apply the style of Pará to the xml element based on the type of master page?

    IM using a flow xml, im importing the xml to be used across different master page templates and I want to apply paragraph styles different items depending on what master page xml, they are on...

    So I have 3 put templates in place

    Type of page 1

    Type of page 2

    Type of page 3

    and 3 paragraph styles

    style 1

    style 2

    style 3

    I have the same xml structure deposited on each page...

    < Entry >

    < name > Page < / name >

    < / name >

    So, can I use javascript to apply the paragraph (style 1) style to the xml element (name) on any page that uses the master page (type of Page 1)

    Is this possible? whether and how this could be done?

    Thanks in advance

    Hello

    Try:

    #include '... / XML rules/glue code.jsx ";

    myDoc var = app.documents.item (0);

    var myRuleSet = new Array (new applyParaStyle());

    {with (MyDoc)}

    var elements = xmlElements;

    __processRuleSet (Elements.Item (0), myRuleSet);

    }

    function applyParaStyle() {}

    myIdName = "Xp".

    This.XPath = "//restaurant_name";

    This.Apply = function (myElement, myRuleProcessor) {}

    {with (MyElement)}

    {Switch(insertionPoints[0].parentTextFrames[0].) ParentPage.appliedMaster.Name)}

    case "X-Master:

    App.Select (texts);

    App.Selection [0]. FillColor = myDoc.colors.item ("xxxx");

    break;

    case 'guide-Scotland:

    App.Select (texts);

    App.Selection [0]. FillColor = myDoc.colors.item ("scotland");

    by default:

    break;

    }

    }

    Returns true;

    }

    }

  • Create the XML element for the cell in the chart CC2015

    Hello world

    I am currently working with the xml element.

    And I want to create xml, table cell element.

    For now, I can create xml for the graphic cell by select graphic image of that cell, and then call the AutoTag() function.

    But I want to create an xml element of a chart without selected cell.

    I found the function () Utils < IXMLElementCommands >-> CreateElement()

    but it doesn't seem to work with a graphic table cell structure.

    Does anyone know how to do?

    Thanks in advance.

    Try,

    InterfacePtr cellContent (tableModel-> QueryCellContentBoss (gridAddress));

    if(cellContent == Nil) {}

    break;

    }

    InterfacePtr cellXMLReferenceData (cellContent, UseDefaultIID());

    {if(!cellXMLReferenceData)}

    break;

    }

    XMLReference cellXMLRef is cellXMLReferenceData-> GetReference();.

  • WTH?  I have a gap in the text that I can't fill.  There is no hidden formatting that I can find, and I apply a paragraph style to text.

    WTH?  I have a gap in the text that I can't fill.  There is no hidden formatting that I can find, and I apply a paragraph style to text.

    I'm not well-versed in indesign, but what I've discovered, is that the box around the page number on the master was wrapping text, which was originally my text to break around her at the center bottom of the pages.  Problem solved, and amiellemiel is right.

  • I need the XML elements appear in the various paragraphs...  Could do with a script?

    I need of the XML elements appear in different paragraphs ...
    Pourrait to do this with a script?

    Thank you...

    You can use this / Puedes usar esto

    insertTextAsContent("\n",XMLElementPosition.beforeElement);
    //  or
    insertTextAsContent("\r", XMLElementPosition.afterElement);
    

    Necesitaria mas information,

  • Why apply a paragraph style let substitutions sometimes? How to prevent this?

    Sometimes when I apply a paragraph of a text style he chooses replace some attributes, making me have click on the button "ignore substitutions" constantly. If I tell indesign to apply a paragraph style why it assumes that my intention was not to implement also the font weight or other random attributes? I can't seem to find the reason for it or how to prevent it, your time and cause errors of formatting if I missed something. Any ideas? No style of characters used in the document.

    Thank you!

    If you want to remove manual replacements you must hold down the ALT key when you apply the style.

    And for the local formatting, you must use character styles.

  • How to add content in the xml element?

    I need to insert a word sqrt (plain text without tags) in the xml element of m:msqrt as below:

    enter image description here

    I tried,

         

    var path = (app.activeDocument.fullName.parent.fsName) m:System.NET.SocketAddress.ToString () replace (/ \ / g, ' /'); document path (sample.indd) active

    var xmlPath = (app.activeDocument.fullName.parent.fsName) m:System.NET.SocketAddress.ToString (.replace(/\\/g, '/')) + "" / with_aid2.xml ";"

    xmlFile = file (xmlPath);

    {if (xmlFile.Exists)}

    xmlFile.open ();

    var myString = xmlFile.read ();

    xmlFile.close ();

    myXml = new XML ();

    myXml = XML (myString);

    var msqrtCount = myXml.xpath("//m:msqrt");

    } else {alert (xmlPath + "does not exist!") ;}}

    for (var i = 0; i < msqrtCount.length (); i ++) {}

    var added = msqrtCount [i];

    added.contents = "sqrt";

    }

    I get an error indicates the invalid content property.

    Try this,

    var myDoc = app.activeDocument;
    mySqrtTag(myDoc)
    function mySqrtTag(elm)
    {
        for (var i = 0; i < elm.xmlElements.length; i++)
        {
            if(elm.xmlElements[i].markupTag.name.toString() == "m:msqrt")
            {
                elm.xmlElements[i].insertionPoints[0].contents = "sqrt";
            }
            mySqrtTag(elm.xmlElements[i]);
        }
    }
    
  • How to separate the content of the XML element

    Hi all

    How can we separate content of the XML element in two strings, where each string will be copied to new variables.

    For ex:
    The entry that I get is

    C:/documents/sharedFiles/Apple.PDF < XmLElement > < / XMLElement >

    now I want to break the content into two parts as

    < yyyy > C:/documents/sharedFiles / < / aaaaa >
    Apple.PDF < bath > < / bath > (I want to separate the file name string)

    and now I want to copy it in two other variables. How can I achieve this in BPEL. Appreciate your help.

    Thank you

    Published by: kameshb on March 25, 2013 11:16

    Hi Philippe,.

    I tried this on a simple XSL and achieve the desired results:

    Entry:
    ------------

    C:/test/dummy/post/test.PDF










    It will be useful.

    Thank you
    Deepak.

  • Loop through all of the xml elements

    How do I loop over all xml tagged in a story? I created a reference to the xml elements of the story I want to like this:

    var xmlStory = myDoc.xmlElements[0].xmlElements[0];
    

    In this structure, I have items < v > 10 / < v >, which I want to change of < id v '10' = > 10 / < v >. I want to do in the InDesign scripting and not with XSL export because of workflow, I plan. I know I can loop on children in the structure like this:

    for(var i=0;i<xmlStory.xmlElements.length;i++){
                        if(xmlStory.xmlElements[i].markupTag.name == "v"){
                                  xmlStory.xmlElements[i].xmlAttributes.add("id", xmlStory.xmlElements[i].contents);
                       }
             }
    

    This works very well for the first level, but I want to find all elements with the tag '< v >. These tags can appear at any level in the structure. How can I make sure that all of them are included and not just the first elements of the child of the element of the story?

    Try this,

    #target inDesign;

    var doc = app.activeDocument;
    xmlTag var = doc.xmlElements [0];
    var vTag = xmlTag.evaluateXPathExpression("//v")
    for (var i = 0; i)<>
    {
    Try
    {
    vTag [i].xmlAttributes.add ("id", vTag [i].xmlContent.contents)
    }
    {catch (e)}
    }

  • How can I save the references to the elements of the xml elements page?

    Hello

    I am trying to add coordinates of the page elements to their associated as xml attributes xml elements.

    I can easily create xml help items

    myDocument.mapStylesToXMLTags ();

    Now, I want to browse the xml document and find details of each element of the associated page and then add them in the corresponding as attributes xml node.

    In other words, I'm trying a code (assuming that all the nodes as children of the root for simplicity) as follows:

    for (var i = 0; i < myRootXMLElement.xmlElements.length; i ++) {}

    var myElement = myRootXMLElement.xmlElements.item (i);

    var myElementsPageItem = * did not find a reference of function / correct documents *.

    var myBounds = myElementsPageItem.visibleBounds;

    addORupdate (myElement, "y1", myBounds [0]);

    addORupdate (myElement, ' x 1', myBounds [1] ");

    addORupdate (myElement, "y2", myBounds [2]);

    addORupdate (myElement, ' x 2', myBounds [3] ");

    }

    In my example of document all the xml that is created by mapStylesToXMLTags() are history of type.

    So I need a way to refer to the corresponding (or rectangle) page element of the history so that I can add information about contact information item xml as attributes.

    Thank you very much...

    myElement.xmlContent.parentTextFrames was not defined in the xml document that is generated by mapStylesToXMLTags()

    After some research the object model, I found my data in

    myElement.xmlContent.textContainers [0]

    Thank you

    Halin

  • Default fonts to 50 points when you apply a paragraph style

    I ran into this many times.  To update a file, InDesign from a previous version (now using CS5) when I apply a paragraph style, the default font is 50 points no matter the style settings.  Is it possible to avoid this.  Currently, I copy and paste the chart into a new file and have to set the text.  If I copy some old text, it causes the same problem.

    Most of our text is copied and pasted from Microsoft Word (old version and new text changes), however, the text that was already in the document and the new text both do the same thing when a style is applied.

    CS5

    Win 7 Pro 64-bit

    Your styles are based on standard paragraph, or is it an applied character style? If so, check to see if any of them have 50 as the size.

  • How Referance groups paragraph Style in the Code?

    How reference to a paragraph in style Group before a paragraph style in the code? My "Heading 1" paragraph style is in a group, called "headings".

    myStyle = app.activeDocument.paragraphStyles.item("Heading 1");
    myStyle.appliedFont = "Microsoft JhengHei";
    
    

    Region Capture.png

    Richard:

    I build a large number of files Indesign containing the tag text, and this is an example of what I am at the beginning of the line when the style is located in a group.  The style name is "AGBoldCtr" and it is located in the group "xSports."

    American League

    In the code, I create a variable for a style to a group like this:

    var PPHead = app.activeDocument.paragraphStyleGroups.item("xSports").paragraphStyles.item ("AGPPHead");

    Then, I attribute PPHead variable of a paragraph as in:

    app.activeDocument.selection [0] .paragraphs [iLoop] .appliedParagraphStyle = PPHead;      //

    Dick Conrad

  • Mac keeps crashing "no directory for the bundleID element: com.apple.cloudd.

    My mac mini crashes several times a day.  I have collected several Console logs when the accident took place (see below for more details).  It seems that the problem is:

    "No directory for the bundleID element: com.apple.cloudd.

    I'd like to find out program that is causing the computer down (full machine reboots)?  How can I solve this problem?

    A few details...

    = Presentation of the material =.

    Model name: Mini Mac

    Model identifier: Macmini7, 1

    Processor name: Intel Core i5

    Processor speed: 2.6 GHz

    Number of processors: 1

    Total number of cores: 2

    (By heart) L2 Cache: 256 KB

    L3 Cache: 3 MB

    Memory: 8 GB

    Boot ROM version: MM71.0220.B03

    Version of the SCM (System): 2.24f32

    Serial number (System): C07NT9MAG1HW

    Material UUID: FDCB795C-A2BF-5D6D-94F3-F98871A90B89

    = NEWSPAPERS FOR EXAMPLE 1 =.

    Crash at 07:22 (screen displayed this time on the clock at the time of the accident)

    30/11/15 7:16:03.742 PM DashlanePluginService [29307]: iextension: here?

    7:19:40.671 30/11/15 PM firefox [21134]: set intl.ime.nstextinput.enable to true in: config to the difficulty of entry.

    30/11/15 com.apple.WebKit.WebContent [22900 7:20:37.499 PM]: ignoring controlTimebase defined by customer, because AVSampleBufferDisplayLayer has been added to a Synchronizer

    30/11/15 com.apple.WebKit.WebContent [22900 7:20:45.263 PM]: ignoring controlTimebase defined by customer, because AVSampleBufferDisplayLayer has been added to a Synchronizer

    7:20:55.956 30/11/15 PM firefox [21134]: set intl.ime.nstextinput.enable to true in: config to the difficulty of entry.

    30/11/15 7:25:11.064 PM distnoted [271]: time absolute # distnote proxy server: time civil 102.815157338: Mon Nov 30 19:25:11 2015 pid: 271 uid: 504 root: no

    30/11/15 7:25:12.403 PM nsurlsessiond [281]: no directory for the bundleID element: com.apple.cloudd

    30/11/15 7:25:13.712 PM ReportPanic [280]: unable to connect (panicHeaderLabel) out of (ReportPanicAppDelegate) (NSTextField): missing setter or instance variable

    30/11/15 7:25:13.712 PM ReportPanic [280]: unable to connect (panicMessageLabel) out of (ReportPanicAppDelegate) (NSTextField): missing setter or instance variable

    30/11/15 7:25:13.712 PM ReportPanic [280]: unable to connect (reportButton) out of (ReportPanicAppDelegate) (NSButton): missing setter or instance variable

    30/11/15 7:25:13.715 PM ReportPanic [280]: ReportPanic cannot stat /Library/Logs/DiagnosticReports/Kernel_2015-11-24-214348_kelley2015s-Mac-mini.p anic

    30/11/15 7:25:14.324 PM pboard [292]: try to break the link previous memory shared when starting returned an error.  Continue...

    = NEWSPAPERS FOR EXAMPLE, 2 =.

    Crash at 08:55 (screen displayed this time on the clock at the time of the accident)

    8:54:09.088 26 11 15 PM QuickLookSatellite [4488]: could not get the extension of sandbox for path=/Users/family/Library/Caches/com.apple.quicklook.satellite. Errno:1

    8:54:09.088 26 11 15 PM QuickLookSatellite [4488]: could not get the extension of sandbox for path=/Users/family/Library/Caches/com.apple.quicklook.satellite. Errno:1

    8:55:10.785 26/11/15 PM firefox [326]: set intl.ime.nstextinput.enable to true in: config to the difficulty of entry.

    8:57:58.043 26 11 15 PM distnoted [266]: time absolute # distnotete proxy server: time civil 114.108837760: Thu Nov 26 20:57:58 2015 pid: 266 uid: 504 root: no

    8:58:04.336 26 11 15 PM ReportPanic [271]: unable to connect (panicHeaderLabel) out of (ReportPanicAppDelegate) (NSTextField): missing setter or instance variable

    8:58:04.336 26 11 15 PM ReportPanic [271]: unable to connect (panicMessageLabel) out of (ReportPanicAppDelegate) (NSTextField): missing setter or instance variable

    8:58:04.336 26 11 15 PM ReportPanic [271]: unable to connect (reportButton) out of (ReportPanicAppDelegate) (NSButton): missing setter or instance variable

    8:58:04.421 26 11 15 PM ReportPanic [271]: ReportPanic cannot stat /Library/Logs/DiagnosticReports/Kernel_2015-11-24-214348_kelley2015s-Mac-mini.p anic

    8:58:04.426 26 11 15 PM nsurlsessiond [272]: no directory for the bundleID element: com.apple.cloudd

    These must be run as administrator. If you have only one user account, you are the administrator.

    Run the Console application in one of the following ways:

    ☞ Enter the first letters of his name in a Spotlight search. Select from the results (it should be at the top).

    ☞ In the Finder, select go utilities ▹ of menu bar or press the combination of keys shift-command-U. The application is in the folder that opens.

    ☞ Open LaunchPad and start typing the name.

    In the Console window, select

    DIAGNOSIS AND diagnostic USE information reports ▹ System

    (not diagnose them and use Messages) in the list of logs on the left. If you don't see this list, select

    List of newspapers seen ▹ display

    in the menu bar.

    There is a disclosure triangle to the left of the list item. If the triangle is pointing to the right, click it so that it points downwards. You will see a list of reports. A report of panic has a name that begins with "Kernel" and ends with ".panic." Select the most recent. The content of the report is displayed at right. Allows you to copy and paste to validate all of the content, text, not a screenshot.

    If you don't see any report, but you know, there was a panic, you have chosen diagnostic and using the list of Log Messages. INFORMATION on the USE of DIAGNOSTIC AND choose instead.

    In the interest of privacy, I suggest that, before posting, you change the UUID ' anonymous, ' a long string of letters, numbers and dashes in the header of the report, if it is present (it cannot be). "

    Please do not post other types of diagnostic report.

    I know that the report is long, perhaps several hundred lines. Please report all this anyway.

    When you post the report, an error message may appear on the web page: "you have included content in your post that is not allowed", or "the message contains invalid characters." It's a bug in the forum software. Thanks for posting the text on Pastebin, then post here a link to the page you created.

    If you have an account on Pastebin, please do not select private in exposure menu to paste on the page, because no one else that you will be able to see it.

  • I bought Adobe Elements with my camera.  Can I switch to Lightroom with some type of credit for the purchase, I already have?

    I bought Adobe Elements with my camera.  Can I switch to Lightroom with some type of credit for the purchase, I already have?

    I don't think that there is any such path upgrade to Lightroom. Lightroom can work with Photoshop Elements or Photoshop as a complementary product to improve and provide features that are not possible in Lightroom itself. For example, with Lightroom, it is extremely difficult if not impossible to remove unwanted objects from an image. Or, there may be sometimes a few necessary dusting that Lightroom cannot do just effectively on its own. If Lightroom offers an easy way to move from Photoshop or Photoshop Elements image in order to more easily accomplish some of these specialized tasks.

Maybe you are looking for