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]),aDoc.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...