Add the double name of the hyperlink (MonLienHypertexte, MonLienHypertexte (2), etc.).

Hello

I am writing a script which automatically creates hypertext links, based on source XML-tag references in a text and their counterparts identically marked in the reference list. It works fine, except that a reference is sometimes mentioned twice in a text, causing the hyperlink to have the same name and crashing the script. I would like to have the names of hyperlink automatically added with (2), (3) etc. If this happens. I tried before with if/else statements, but unfortunately without success.

My current script, without the addition:

// General declarations
var myDocument = app.activeDocument;   
var myRootXML = myDocument.xmlElements[0];   
    
// Include glue code
#include "glue code.jsx";

// Some main definitions
main();
function main(){
    if (app.documents.length != 0){
        var myDocument = app.documents.item(0);
        //This rule set contains a single rule.
        var myRuleSet = new Array (new findCitationRef);
    with(myDocument){
        var elements = xmlElements;
        __processRuleSet(elements.item(0), myRuleSet);
        }
    }
    else{
        alert("No open document");
    }
}

// Define function findCitationRef
function findCitationRef() 
    {
      this.name = "findCitationRef";
      this.xpath = "//CitationRef";
      this.apply = function(myXMLPathSource, myRuleSet){    
         with(myXMLPathSource){

             var myXMLPathSourceID = myXMLPathSource.xmlAttributes.itemByName("CitationID").value;
              var myXMLPathDestinationID = myXMLPathSource.xmlAttributes.itemByName("CitationID").value;          
              var myXMLPathDestination = myRootXML.evaluateXPathExpression("//Citation[@ID='" + myXMLPathDestinationID + "']"); 
              $.writeln(myXMLPathDestination[0].contents);          
              
              var citationRefAnchor = myXMLPathSource.texts;
              var citationDestination = myXMLPathDestination[0].texts;
              // Store as a variable
                               
              var myHyperlinkSource = myDocument.hyperlinkTextSources.add(citationRefAnchor);  
              var myTextAnchor = myDocument.hyperlinkTextDestinations.add(citationDestination);  

              var myHyperlink = myDocument.hyperlinks.add(myHyperlinkSource, myTextAnchor, {name: "Hyperlink " + myXMLPathDestinationID });
              
              false;

          }
        }  
     };

 // Call function findCitationRef
 findCitationRef();

My miserable attempt so he could work, that will not cross the first hyperlink:

// General declarations
var myDocument = app.activeDocument;   
var myRootXML = myDocument.xmlElements[0];   
    
// Include glue code
#include "glue code.jsx";

// Some main definitions
main();
function main(){
    if (app.documents.length != 0){
        var myDocument = app.documents.item(0);
        //This rule set contains a single rule.
        var myRuleSet = new Array (new findCitationRef);
    with(myDocument){
        var elements = xmlElements;
        __processRuleSet(elements.item(0), myRuleSet);
        }
    }
    else{
        alert("No open document");
    }
}

// Define function findCitationRef
function findCitationRef() 
    {
      this.name = "findCitationRef";
      this.xpath = "//CitationRef";
      this.apply = function(myXMLPathSource, myRuleSet){    
         with(myXMLPathSource){

          // Save the CitationRef ID to the variable, for future reference
          var myXMLPathSourceID = myXMLPathSource.xmlAttributes.itemByName("CitationID").value; 
      
          $.writeln("Eerste bevestiging: " + myXMLPathSource.contents + ": " + myXMLPathSourceID); // TO BE REMOVED
          $.writeln("Tweede bevestiging: " + myXMLPathSource.xmlAttributes.itemByName("CitationID").value); // TO BE REMOVED
          
          // Save the ID for the corresponding Citation        
          var myXMLPathDestinationID = myXMLPathSource.xmlAttributes.itemByName("CitationID").value;   
          
          // Find the corresponding Citation using aforementioned ID
          var myXMLPathDestination = myRootXML.evaluateXPathExpression("//Citation[@ID='" + myXMLPathDestinationID + "']");  
          $.writeln(myXMLPathDestination[0].contents);          // TO BE REMOVED
          
          // Store source and destination items in variables for future use in hyperlink
          var citationRefAnchor = myXMLPathSource.texts;
          var citationDestination = myXMLPathDestination[0].texts;
                           
          // Create the hyperlink source and destination
          var myHyperlinkSource = myDocument.hyperlinkTextSources.add(citationRefAnchor);  
          var myTextAnchor = myDocument.hyperlinkTextDestinations.add(citationDestination);  
              
          //Then, create the hyperlink, but first...
                //... check if there's already at least one hyperlink
                if(!myDocument.hyperlinks[0].isValid) //
                {
                    // If not, that's where we'll create it
                    var myHyperlink = myDocument.hyperlinks.add(myHyperlinkSource, myTextAnchor, {name: myXMLPathSourceID});
                }

                // Otherwise, if there is at least one hyperlink...
                else 
                {     
                    // Go through all the hyperlinks
                    for(count=0; count<myDocument.hyperlinks.length; count++){
                        // If there's one with the current ID, create another one, but add the 'b' suffix
                        if(myDocument.hyperlinks[count].name === myXMLPathSourceID) {
                            var myHyperlink = myDocument.hyperlinks.add(myHyperlinkSource, myTextAnchor, {name: myXMLPathSourceID + "b"});

                         }
                        else // If there's none with the current ID...
                        {   
                            // Check if you've previously created one, and if not, create one:
                            if(!myDocument.hyperlinks[count].isValid) {
                            var myHyperlink = myDocument.hyperlinks.add(myHyperlinkSource, myTextAnchor, {name: myXMLPathSourceID});
                            }
                            
                            // If not, that's fine, we're done here. Let's go check the next citation.
                            else {
                                } 
                           } // End check for the current ID
                    } // Stop going through all the hyperlinks
              } // Stop checking if there's at least one hyperlink
            }  // Stop going through all the citations
        
        }  
     };

 // Call function findCitationRef
 findCitationRef();


Thanks a lot for all the directions you can give!

Kind regards

Julian

I do something like this:

        //Hyperlink names must be unique. If a hyperlink has already been created with this name, this iterates a number to append
        //to the name in the format "(1)".
        var iter = 0;
       //Check if a hyperlink with the name I want to use already exists and that it isn't this hyperlink.
        while (myDoc.hyperlinks.itemByName(myHyperName).isValid
                && myDoc.hyperlinks.itemByName(myHyperName).source.sourceText !== myThingToHyper){
            //Bump up the number to append by one.
            iter++;
           //Change the hyperlink name so that the old number is replaced with the new one.
            myHyperName = myHyperName.replace(/ \(\d+\)$/, "") + " (" + iter + ")";
        }

You could change that to add a letter instead. the best way I know this is to create a string variable that contains the alphabet and slice the letter you need, but it could be any other way.

I think the problem with your script, it's that you're not accounting for cases where there is more than two hyperlinks with the same name. You want to use a while loop so you keep looping until you hit a number or a free letter.

Tags: InDesign

Similar Questions

  • Add the hyperlink recompose document

    Hello

    I get documents of a company who uses hyphenation specific plugin which is their own.

    I a script that adds hyperlinks by using:
    -linkDestination = myDocument.hyperlinkURLDestinations.add
    -linkSource = myDocument.hyperlinkTextSources.add
    -then myDocument.hyperlinks.add (linkSource, linkDestination, {name: Nom_lien_hypertexte});
    It causes the reconstruction of the text with different hyphenation I have not (and should not) have the specific unhappy plugin.

    Is there a way to create hyperlinks without the current document recomposed (in fact no text or the style has changed, there is no need to recompose)?

    Kind regards

    Lionel

    PS: I use indesign CS5.5

    Yes, to my dismay, I saw this happen on complete documents in the case: adding a simple XML or a hyperlink tag - that should have been totally transparent for text - suddenly made the text re - dial.

    A possible solution for Lionel is to create rectangles on top of the text and assign hyperlinks to them instead. These rectangles could be created on a layer that is clean, so that they are eliminated easily if the text is changed.

    A small disadvantage is that you can measure, down, left and right of the text - but not by the top! However, you can kind of fake it: make the rectangle a leader high amount and move it down by about a 1/3 of its height (eye or result).

  • Add the hyperlink to the real banner

    Hy. I just finished my banner but I need to add a hyperlink to a specific address. How this can be done? I'm quite new with Flash so please be detailed with the news.

    Thank you!

    For the hyperlink to a web page, you can use navigateToURL() in conjunction with a button and event-handling code.  Create the button/movieclip/sprite, place it on the stage where you want the interaction to occur and then give it a name of instance via the properties panel.  Let's say you name "btn".

    Then place the following code in a new layer of the timeline in the same numbered box where is the button.

    btn.addEventListener (MouseEvent.CLICK, clickedLink);

    function clickedLink(evt:MouseEvent):void {}

    var url: String = "http://, etc.;  / assign the address hyperlink in quotes

    navigateToURL (new URLRequest (url), "_blank");

    }

    If you wish to have the new open web page in the same browser window, replace "_blank" by "_self".

  • 5.5 - How to add the hyperlink to URL on the page of the quiz?

    Hi, I have a PPT background imported by hyperlinks to URLS. As-is, the work of hyperlinks to fine in Captivate. My problem is that I want it to be a background in a slide of questionnaire. (The quiz slide is a corresponding slide. I wish that the answers on the slide to hyperlink to the URL with more information on the topics. If the user does not know the answer by the view, he or she can open the hyperlink, do a little reading and research, and then choose an answer on the questionnaire slide.) These are the solutions I've tried:

    • Copied and pasted slide as a background in a slide of questionnaire - hyperlinks do not work. (I assume that it uses the background image only).
    • Deletion of hyperlinks in PPT slide - imported into Captivate - attempted to create the quiz slide hyperlinks using text boxes or click on the boxes - cannot add those. (I guess that Captivate does not allow any other interactive buttons on his quiz slides.?)
    • Abandoned on the groundswell - tried default hyperlink Question and Answer buttons slide quiz - can't do. (I guess that Captivate does not have to perform several actions, objects of default quiz.?)

    I would appreciate any advice you might have. Is my only option to create an additional slide with hyperlinks and then provide a separate questionnaire slide? ("Click on the links below to learn more about these topics. Then move to the next slide to complete the corresponding fiscal year. ") I guess that will work, but it seems awkward.

    Thank you very much.

    In 6 Captivate, you can add a form button to a question slide, and it has "Open URL" in its list of possible actions. More information on the buttons of form in this blog post:

    http://lilybiri.posterous.com/want-a-button-on-question-slide-in-Captivate

    I recently presented a webinar for Adobe on these form buttons. In this blog, you will find the link to the recorded webinar:

    directories - actions.html http://blogs.adobe.com/Captivate/2012/09/Training-lilybiris-Favourite-Shapes-to-Trigger-ad

    You cannot add interactive objects to a question slide in Captivate 5.5.

    Lilybiri

  • How to add the hyperlink in the page of the ofa

    Hi all


    I have a requirement where I have a table in the form OPS with 5 columns, only a single column called pageid page; page id values must be hyperlink.
    so when the user clicks on the hyperlink, it must open a page with empty fields, so that the user can enter data and click Save button.
    Please someone tell me how to get this.or to give me links to simlilar it can help me :-)
    Thank you.

    Hello

    * / oracle/apps/fnd/frame/box in tools/labsolutions/webui/EmpDetailsPG * is the page where you want to navigate after clicking on the link, empNum and empName are the variable that will be passed to the next page and you can get the value of these variables in method PR only @EmployeeName and @EmployeeId are the way to assign the value of an attribute VO of the page where the link is created the value will be assigned to empNum, empName.

    Thank you
    Pratap

  • Add the hyperlink to an email

    I'm trying to add a hyperlink to a local document (Excel file) in the body of an email.  I use 'SMTP Email send message' and tried wiring of several different string formats the body trying to attach a hyperlink and have had no luck.

    Any ideas?  I have the report generation tool, but do not have the Internet Toolkit.

    Thank you very much

    Mark

    By inserting file:/// before the file name, a local link linkable was created.  When read by mail Outlook/program that appears as a link.

    i.e."file:///C:\Documents and Settings\user\excelsheet.xls" would connect to the Excel worksheet.  This method works for local files.

    Mark

  • Add the hyperlink by script

    Hello

    Is it possible to add hyperlinks in javascript, so that they can be assigned later in the document? Let me explain my thoughts:

    hyperlink.jpg

    This screenshot shows a list of the various documents (001 to 005) and the URL for the first document. I have a hyperlink to each of them automatically. Because the file is saved as 54K0504001.indd, I think it's possible.

    What should I need:

    1. a pop up with a question: "how many hyperlinks to do."

    2. According to the reply, creation of new hyperlinks in the Panel with the full URL (if the answer is 2, I should get 2 links hyperlink, http://www.dekamer.be/FLWB/PDF/54/0504/54K0504001.pdf , and http://www.dekamer.be/FLWB/PDF/54/0504/54K0504002.pdf

    OK, clear. It sounds simple enough:

    main();
    
    function main() {
        var num = prompt ('How many hyperlinks?', '1', 'Create hyperlinks');
        if (num === null) {
            exit();
        }
    
        function pad (n) {
            return ('00'+n).slice(-3);
        }
    
        var base = 'http://www.dekamer.be/FLWB/PDF/54/0504/54K0504';
        for (var i = 1; i <= num; i++) {
            var hl = base+pad(i)+'.pdf';
            app.documents[0].hyperlinkURLDestinations.add(hl, {name: hl});
        }
    }
    

    You could probably automate completely, but it is more work.

    Peter

  • How to add the hyperlink on front panel

    Hello

    I want to add hyperlinks on my front. After clicking on who can access run another VI of disc or simply give me the functionality of a booleon control.

    I don't want to use the button for this.

    I want these hyperlinks for my standalone application main menu items.

    Have you tried a search? This has been asked before, and the proposed solutions were provided. See, for example

    http://forums.NI.com/T5/LabVIEW/do-you-know-how-to-create-front-panel-like-Web/m-p/1289778

    I think there may have been an idea posted in the Exchange of LabVIEW ideas as well. If this is not the case, do not hesitate to submit a suggestion so it can be voted on.

  • How we can add the hyperlink in the screen.

    Hello

    I want to add a hyperlink in the window that opens another screen. How we achieve this.

    Take a look at this thread.

    http://supportforums.BlackBerry.com/T5/Java-development/make-an-email-label-clickable/m-p/19496#m65

    Concerning

    Bika

  • Programmatically add the hyperlink to TextFlow

    Hello

    Currently, I add hyperlinks to a TextFlow as follows:

    public function setHyperLink( linkInput:String ):void
    {
         if (editor.selectionActivePosition != editor.selectionAnchorPosition)
         {
              var content:String = TextConverter.export(editor.textFlow , TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE).toString();
              var selection:String = editor.text.substring(  editor.selectionAnchorPosition,editor.selectionActivePosition );
              var text:String = TextConverter.export( editor.textFlow, TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE ).toString();
              var arr:Array = text.split( selection );               
              var output:String = arr[0]+"</span>" + 
                                            "<a href='"+linkInput+"' target='_blank'>" +
                                 "<span>"+selection+"</span>"+
                             "</a>" +
                             "<span>"+arr[1];
                   
              editor.textFlow = TextConverter.importToFlow( output, TextConverter.TEXT_LAYOUT_FORMAT );               
         }
    }
    

    It works fine until the selection: the string is '2008', which leads to a divided since the markup String contans 2008 incorect:

    "< TextFlow whiteSpaceCollapse ="preserve"version ="2.0.0"xmlns =" http://ns.Adobe.com/TextLayout/2008 ">"

    Anyone see an another way to get the textflow before and after a certain position?

    Probably with "editor.textFlow.shallowCopy"? But I have FlowElements.

    But how to join these FlowElements and my hyperlink together as textflow?

    beforeLinkFlowElement + link + afterLinkFlowElement?

    ...

    How to add links in this demo:

    http://labs.Adobe.com/technologies/TextLayout/demos/

    ?

    [EDIT:]

    OK found:

    http://tourdeflex.Adobe.com/Flex4.0/tlf/srcview/index.html

    I'll study this now

    [EDIT:]

    OK I found that works, but how to set the default bind / the appearance of color? There is no default value after the application of this function?

    private void changeLink(urlText:String,_targetText:String,_extendToOverlappingLinks:Boolean):void

    {

    if (activeFlow & & activeFlow.interactionManager is IEditManager)

         {

    IEditManager (activeFlow.interactionManager).

    IEditManager (activeFlow.interactionManager) .applyLink (urlText, targetText, extendToOverlappingLinks);

    activeFlow.interactionManager.setFocus ();

         }

    }

    These Interfaces make it quite difficult to understand

    If you find that the appellant in the tlf is null object, pls create it yourself.

    tf.linkNormalFormat = new TextLayoutFormat();
    tf.linkNormalFormat.color = 0xFF0000;

    There are some attribute objects in TLF you need to deal with as the case may be, for example textflow.interactionManager.

  • How to add the hyperlink to the full report

    Hello

    I have a report and the last line display total report (using default apex - check check sum).



    My last line like below
    ------------------------------------------------------
    Total report | 10. 20. 30. 0 | 100.
    ------------------------------------------------------

    My requirement to add hyper link to the numbers 10, 20, 30, 0, 100 total for the report.

    Any help will be much appreciated.

    Thanks in advance

    Shijesh,

    There is really no way to do this. I only really see a way - jQuery. You will need to start by entering in the report and by replacing the "display this text when you print the report amounts" with something like:

    <span id="repTotals">Total:</span>
    

    This will give something to recover for jQuery. From there, you will have to go up to the line, then in specific columns of the line by replacing the content that the page loads with your hyperlinks.

    Kind regards
    Dan

    http://danielmcghan.us
    http://sourceforge.NET/projects/tapigen

  • Add the hyperlink in a page to direct to a .pdf report in oracle jdeveloper, ADF

    Hello

    I want to put a hyperlink, which will lead the user to the report. but I have the problem with, "where should I put the pdf file" any help please?

    Here is my code:

    < a target = "_blank" href =' / faces/DocumentationKNM.pdf '> Guide Book < /a >

    What should be the href?

    Well, it depends of course when the pdf report can be found on your server, and if it is accessible from the web application. For this, it must be somewhere in the web root of your application. To access the report somewhere else on the server, you can implement a servlet and circulate the report from there.

    Summary: we need describe your use cases in more detail.

    Timo

  • Add the hyperlink to open a falsh movie

    Hello

    In Captivate 4: I am looking for a way to add a link to one of the slides that will open a URL.

    Is it possible to do?

    Thank you

    Merav.

    Hi Lilybiri

    The scenario seems to me that the object button is pause the slide before click, no areas? So if the blade is paused and the click boxes don't release the break when they click, by disabling the option "Continue", would not keep the playhead paused?

    Note that I didn't set up a corresponding scenario to fully test, but it seems to me that this is how it would work.

    See you soon... Rick

    Useful and practical links

    Captivate wish form/Bug report form

    Certified Adobe Captivate training

    SorcerStone blog

    Captivate eBooks

  • You can change/add the Menu (File, Edit, Favorites etc.) in the planning?

    Hello

    That's the question related to the queue, Edit, Favorties, help and other options menu that are present in the planning. I wanted to know if we could add custom Menus it?
    I want to add a Menu he and below which a link that takes me to a different place.
    Please let me know!

    ~ Hervé

    Published by: Hervé August 25, 2011 06:37

    You can use menus on the right-click event on forms of data for the same thing, as far as I know he has no direct way to add more options next to the queue, Edit etc.
    You can take a look at:
    Specification of custom tools
    http://download.Oracle.com/docs/CD/E12825_01/EPM.111/hp_admin/tools.html
    Menus:
    http://download.Oracle.com/docs/CD/E12825_01/EPM.111/hp_admin/menu_ed.html

    See you soon. !

  • Effect of substitution does not work once I have add the link

    I have a photoshop button that has 2 States: Normal and rollover. Rolling works before you add a hyperlink to it, but when I add the hyperlink and listen to extracts from the website, the bearing stops running. Can you explain where I'm wrong? The transition works fine until I have add the link.

    Thanks for your help!

    The only way that it would not work is if you are linking to the same page as you. Other than that, the only other explanation is that your Muse program has a bug.

Maybe you are looking for

  • Variables shared on the CFP becomes zero and communicate with the PSC

    I use a PC with two network cards, one on one wired ethernet, the other on a private IP directly connected to a PSC-2120 (running 6.0.5 full). I use variables shared on the CFP and aliasing to static variable on the PC (initially LV 8.6, now 2009f2 w

  • waveform cursor

    I would like to create my waveform with slider 2, I set the beginning and the end (with the cursor), where that only that (with the 'save' button will save the file (in my case for the test is just in the string);) I create perdnisone waveform, add 2

  • Unable to identify the files audio ripped

    lack of music Ive ripped a mix cd that has music which I don't know and I will identify them so I don't know what im listening but not many programs online help. What I would do.

  • File caricati sul mio account no castroni!

    Ho UN licenza CS5 ita win e relativo adobe account con spazio 2Go sul quale ho caricato some imie files fotografici, da UN mese circa non riesco più a raggiungerli! COSA succede?Grazie

  • Photoshop will close not (mac).

    At the end of the day, then the closing (mac), Photoshop refuses to quit smoking. I end up having to "force quit" to shut down my system.