I've managed to put together a few XSL stylesheets and scripts (perl, awk, bash) to transform my own 'markup' into IDML. (I found this to be the most convenient and reliable method to automate placing footnotes.)
To do that, I've consulted the IDML specifications from Adobe, as well as the official 'cookbook'; and I've tested my XMLs with Adobe's own schemas inside the SDK (via EMacs's nXML mode); and everything is working fine with the documents thus produced—with a single exception: the hyperlinks (to refer to text anchors within the same document).
When I'm referencing 'static' bits of text inside the same document, I prefer Hyperlinking over Cross-Referencing, in that the former allows me to use any text for my links. On the hyperlinks panel, and in the story editor, I do see my IDML-placed hyperlinks; but when exported to pdf or html, they don't work. More precisely, one or two of them work as expected, and the rest is all broken; although there's absolutely no visible difference between the 'source code' for the two kinds.
I prepared several 'templates', in order to see how hyperlinks look when defined inside InDesign, and then exported into IDML. Having examined those, I still can't see what I'm doing wrong.
Acrobat recognizes all of my 'HyperlinkTextDestination's, but not the links themselves; and exporting to IDML/Re-Importing to .indd doesn't help either.
This is hugely frustrating. Now—I'd be really grateful if someone could tell me what's wrong with my link sources and destinations, and so forth, that they refuse to work. I hope it's just that I'm making a careless mistake with the XML attributes and such (I'm a novice in all these matters):
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">
<HyperlinkTextSource Self="#THE UNIQUE ID OF THE DESTINATION, ASSIGNED BY ME#" Name="#UNIQUELY GENERATED (RANDOM) NAME#" Hidden="false" AppliedCharacterStyle="n">
<Content>#THE BIT OF TEXT THAT WILL SERVE AS THE LINK#</Content>
</HyperlinkTextSource>
</CharacterStyleRange>
<HyperlinkTextDestination Self="HyperlinkTextDestination/#THE UNIQUE ID OF THE DESTINATION, ASSIGNED BY ME#" Name="#UNIQUE (RANDOM) NAME#" Hidden="false"/>
<Hyperlink Self="#UNIQUE (RANDOM) NAME#" Name="#UNIQUE ID OF THE DESTINATION, ASSIGNED BY ME#" Source="#UNIQUE ID OF THE DESTINATION, ASSIGNED BY ME#" Visible="false" Highlight="None" Width="Thin" BorderStyle="Solid" Hidden="false">
<Properties>
<BorderColor type="enumeration">Black</BorderColor>
<Destination type="object">HyperlinkTextDestination/#UNIQUE ID OF THE DESTINATION, ASSIGNED BY ME#</Destination>
</Properties>
</Hyperlink>
<xsl:template match="#MY CHOSEN ELEMENT NAME FOR LINKS#">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">
<HyperlinkTextSource Self="{@linkend#THE UNIQUE ID OF THE DESTINATION#}" Name="{@linkend}_{generate-id(.)}" Hidden="false" AppliedCharacterStyle="n">
<Content><xsl:value-of select="."/></Content>
</HyperlinkTextSource>
</CharacterStyleRange>
</xsl:template>
<HyperlinkTextDestination Self="HyperlinkTextDestination/{@id#THE UNIQUE ID, ASSIGNED BY ME#}" Name="{@id#...SAME AS BEFORE#}" Hidden="false"/>
<Hyperlink Self="{@linkend}DEST{generate-id(.)}" Name="{.}" Source="{@linkend}" Visible="false" Highlight="None" Width="Thin" BorderStyle="Solid" Hidden="false">
<Properties>
<BorderColor type="enumeration">Black</BorderColor>
<Destination type="object">HyperlinkTextDestination/<xsl:value-of select="@linkend"/></Destination>
</Properties>
</Hyperlink>
ps. I don't transform into InDesign-XMLElements; all of this becomes regular text. I don't think it's worth the hassle: Id's XML-handling capabilities are too rudimentary.
I was able to solve this, finally. I'm posting the solution here, so that others with similar questions might benefit:
Well, my mistake was this: I transgressed the #1 rule of IDML—if an element has a 'Self' attribute, it has to be unique inside the entire package. I had given the same 'self' attribute, to all links pointing to the same destination. Once I fixed this, the hyperlinks started working. (I should have read the specifications more carefully...)
North America
Europe, Middle East and Africa
Asia Pacific