7 Replies Latest reply on Jul 28, 2010 9:36 PM by PankChat

    [CS4 JS] Create HyperLinks from XMLattributes values

    stoereee Level 1

      Hi,

       

      Is  it possible to make a script to create hyperlinks from imported XML text where there are two elements named "hyperso" as the source of a hyperlink and "hyperde" as the destination of a hyperlink. Each "hyperso" element has got a unique attribute value that is corresponding with de attribute value of element "hyperde". For example:

       

      <hyperso id="1">Source</hyperso>
      <hyperde id="1">Destination</hyperde>


      Sjoerd

        • 2. Re: [CS4 JS] Create HyperLinks from XMLattributes values
          sudar1983_14 Level 2

          XML will not allow "same id with two times". please see the code below, i have changed source attribute to 'ref'.

           

          var scriptTitle="Hypherlink";
          var sourceElement='hyperso';
          var sourceAttribute='ref';
          var destinationElement='hyperde';
          var destinationAttribute='id';
          var requiredElements=new Array();
          var definedElement="";
          var myCharStyle;

           

          aDoc=app.activeDocument;

           

          app.doScript (File(app.filePath+"/Scripts/Xml Rules/glue code.jsx"));

           

          getXMLElements();

           

          if (requiredElements.length > 0)
          {
              //Processing on citation elements
              for(var xEle=0; xEle < requiredElements.length; xEle++)
              {
                  var citationElement=requiredElements[xEle];
                  citationElement.texts[0].fillColor=aDoc.swatches.item('Blue');
                  definedElement="";
                  GetElement(citationElement.xmlAttributes.item(sourceAttribute).value);
                  if (definedElement.markupTag.name == destinationElement)
                  {
                      var myHyperlink=aDoc.hyperlinks.add(aDoc.hyperlinkTextSources.add(citationElement.texts[0]),a Doc.hyperlinkTextDestinations.add(definedElement.texts[0]));   
                      myHyperlink.name="Link "+(xEle+1);
                      myHyperlink.visible=false;
                  }
                  else
                  {
                      alert(definedElement.markupTag.name);
                  }
              }
          }

           

          function GetElement(receivedId)
          {
              //Using XML rule set we get required elements
              var xmlRuleSetDefinition = new Array(new FindDefinitionElement("//*[@"+destinationAttribute+"=\'"+receivedId+"\']"));
              __processRuleSet(aDoc.xmlElements.item(0), xmlRuleSetDefinition);
          }

           

          function FindDefinitionElement(myDefinitionRule)
          {
              this.name = "FindDefinitionElement";
              this.xpath = myDefinitionRule;
              this.apply = function(myElement, myRuleProcessor)
              {
                  definedElement=myElement;
              }
          }

           

          function getXMLElements()
          {
              //Using XML rule set we can get required elements
              var xmlRuleSetCitation = new Array(new FindCitationElement("//"+sourceElement+"[@"+sourceAttribute+"]", requiredElements));
              __processRuleSet(aDoc.xmlElements.item(0), xmlRuleSetCitation);
          }

           

          function FindCitationElement(myCitationRule, myarray)
          {
              this.name = "FindCitationElement";
              this.xpath = myCitationRule;
              this.apply = function(myElement, myRuleProcessor)
              {
                  myarray.push(myElement);
              }
          }

           

           

          Arivu...

          • 3. Re: [CS4 JS] Create HyperLinks from XMLattributes values
            stoereee Level 1

            Thanks, this is very helpfull!!

            • 4. Re: [CS4 JS] Create HyperLinks from XMLattributes values
              Adobe-InDesign CS4 Level 1

              Dear sudar1983

               

              How to use your code in XML namespace contents. currently you are give this sample is normal element based @ the same time some of the xml name space is there in the xml Element then how to handle this script. Please give me suggestion...

               

              Example for the xmlName spaces:

               

              (1) <sb:inter-ref> (2) <nb:hole>

               

              Please I need your help on this area and let me know your comments also.

               

              Thanks & Regards

              T.R.Harihara Sudhan

              • 5. Re: [CS4 JS] Create HyperLinks from XMLattributes values
                கற்பனை (Imagine) Level 3

                Hi Hari,

                 

                Possible to search the namespace element also using the XML Rule processor.  You need to give the element name without namespace in the Xpath rule and you get the result.

                 

                Regards,

                Raj

                • 6. Re: [CS4 JS] Create HyperLinks from XMLattributes values
                  Adobe-InDesign CS4 Level 1

                  Dear Raj,

                   

                  Many thanks for your great and use full Idea. But Still I'm getting the problem in "definedElement.markupTag.name == destinationElement" Checking area, because definedElement is Null value only I recieved.

                   

                  //============================//

                  var scriptTitle="Hypherlink";
                  var sourceElement='cross-ref';
                  var sourceAttribute='refid';
                  var destinationElement='figure';
                  var destinationAttribute='id';
                  var requiredElements=new Array();
                  var definedElement="";
                  var myCharStyle;

                  //==============================//

                   

                  The above sourceElement have "xmlNameSpace" but I used without namespace @ the same time destinationElement also without namespace.

                   

                   

                  One more oblication to you, Please suggest your comments

                  "Possible to search the namespace element also using the XML Rule processor..."

                   

                  How to invoke the namespace in this XML Rule processor script?. Please I need your commets and suggestions.

                   

                  Thanks & Regards

                  T.R.Harihara Sudhan

                   

                  • 7. Re: [CS4 JS] Create HyperLinks from XMLattributes values
                    PankChat Level 1

                    >One more oblication to you, Please suggest your comments

                    >"Possible to search the namespace element also using the XML Rule  processor..."

                     

                    As far as my experienced is concerned, namespace do not support in XML Rule processor. I tried it myself earlier but end up removing namespaces in XPath statement. Though would love to listen experts if there is a way around.

                     

                    --Pankaj