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):
This is how an 'HyperlinkTextSource' looks, inside my main story xml:
<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>
My 'HyperlinkTextDestination's look like this, inside the main story xml:
<HyperlinkTextDestination Self="HyperlinkTextDestination/#THE UNIQUE ID OF THE DESTINATION, ASSIGNED BY ME#" Name="#UNIQUE (RANDOM) NAME#" Hidden="false"/>
And this, the Hyperlink specification inside designmap.xml:
<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>
This is the bit of XSLT that produces the 'source':
<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>
The destination producer:
<HyperlinkTextDestination Self="HyperlinkTextDestination/{@id#THE UNIQUE ID, ASSIGNED BY ME#}" Name="{@id#...SAME AS BEFORE#}" Hidden="false"/>
And, this is responsible for the Hyperlink elements inside designmap.xml:
<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.