0

I've looking for solution on how to create cross-reference using InDesign Tagged Text but I can't find any good suggestion.

Here is my scenario I was task to create a round tripping workflow for XML to InDesign and InDesign to XML or vice versa. I also need to cross-reference for URL and End Notes links.

So first, I have to create and XSLT script that would transform XML to InDesign Tagged Text (I used tagged text because most of our operators still using InDesign CS3). Then after page composition is done we'll have to export InDesign file to XHTML (export for dreamweaver). Create another XSLT script to transform back XHTML to XML to be use for ePub conversion (why not export directly InDesign to ePub? the answer is there's a lot of customization needed).

Below is my XSLT codes to create cross-ref for Tagged Text:

Adding Cross-ref to InDesign:

<xsl:template match="/">
    <--! End Notes -->
    <xsl:text>&#60;XRefFmtDefn:=&#60;FmtNm:ntf>&#60;CharStyleRef:ntf>&#60;BldBlkLen:1>&#60;BldBlk:=&#60;BlkTyp:ParagraphNumber>&#60;CstmTxt:>&#60;CharStyleRef:>&#60;InclDlm:0>>></xsl:text>
    <xsl:for-each select="descendant::apnf">
        <xsl:variable name="num" select="count(preceding::apnf) + 1"/>
        <xsl:text>&#60;HplDestDfn:=&#60;HplDestName:Anchor </xsl:text><xsl:value-of select="$num"/><xsl:text>>&#60;DestKey:</xsl:text><xsl:value-of select="$num"/><xsl:text>>&#60;HplDestIdx:1</xsl:text><xsl:text>>&#60;IsPara:1>&#60;Hid:0>></xsl:text>
    </xsl:for-each>

    <--! URL -->

    <xsl:text disable-output-escaping="yes">&#60;HplDestDfn:=</xsl:text>
    <xsl:for-each select="descendant::libelle[generate-id()=generate-id(key('urlDistinct', @cible)[1])]">
        <xsl:value-of select="concat('&#60;HplDestName:', replace(@cible,'/', '\\/'),'&#62;&#60;DestKey:1&#62;&#60;HplDestUrl:http\:\/\/', replace(@cible,'/', '\\/'), '&#62;')"/>
    </xsl:for-each>
    <xsl:text disable-output-escaping="yes">&#60;Hid:0&#62;&#62;</xsl:text>
    <xsl:apply-templates/>
</xsl:template>

Create cross-ref links for End Notes:

<xsl:template match="apnf">
    <xsl:variable name="num" select="count(preceding::apnf) + 1"/>
    <xsl:text>&#60;cstyle:ntf&#62;</xsl:text>
    <xsl:text>&lt;Hpl:=&lt;HplName:</xsl:text><xsl:value-of select="@id"/> <xsl:text>>&lt;HplDest:Anchor </xsl:text><xsl:value-of select="$num"/><xsl:text>>&lt;DestKey:</xsl:text><xsl:value-of select="$num"/><xsl:text>>&lt;XRefFmt:ntf>&lt;CharStyleRef:>&lt;HplLen:1>&lt;HplOff:0>&lt;Hid:0>&lt;Brdrv:0>&lt;Brdrw:Thin>&lt;Brdrh:None>&lt;Brdrs:Solid>&lt;Brdrc:0\,0\,0>></xsl:text>
    <xsl:value-of select="$num"/>
    <xsl:text>&#60;cstyle:&#62;</xsl:text>
</xsl:template>

Create cross-ref URLs

<xsl:template match="url">
    <xsl:text>&#60;cstyle:url&#62;</xsl:text>
    <xsl:choose>
        <xsl:when test="exists(libelle)">
            <xsl:text>&lt;Hpl:=&lt;HplName:</xsl:text><xsl:value-of select="replace(libelle/@cible,'/', '\\/')"/><xsl:text>&gt;&lt;HplDest:http\:\/\/</xsl:text><xsl:value-of select="replace(libelle/@cible,'/', '\\/')"/><xsl:text>>&lt;DestKey:1>&lt;CharStyleRef:>&lt;HplLen:3>&lt;HplOff:0>&lt;Hid:0>&lt;Brdrv:0>&lt;Brdrw:Thin>&lt;Brdrh:None>&lt;Brdrs:Solid>&lt;Brdrc:0\,0\,0>></xsl:text>
            <xsl:sequence select="libelle/text()"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:sequence select="./text()"/>
        </xsl:otherwise>
    </xsl:choose>
    <xsl:text>&#60;cstyle:&#62;</xsl:text>
</xsl:template>

Here is my problem, when I imported the tagged text to InDesign URL and endnotes has dead links. I suspect it is the destination key, because when I tried to export sample InDesign with working links the destination key is targeting the position of the character where it should be cross-ref.

My questions are:

  1. Cross-Reference is supported in InDesign Tagged Text like ICML does?
  2. Is there's a way I can get position() of character in XML using XSLT (meaning position of character within the whole XML not position within single node)? If is possible maybe I could get destination key correctly.

Any suggestions or recommendations is highly appreciated.

Thanks!

P.S. This link http://forums.adobe.com/message/3978432#3978432 also discussed InDesign Tagged Text for Cross-reference Entries but there is no complete solution is given.

rhemb
  • 45
  • 1
  • 7

1 Answers1

1

Just tested this for myself. It is possible to add cross-references to the tagged text before it is imported, but like you noted, you will have to find the character position of the cross-reference destination compared to the whole document. This sounds difficult and error prone, especially when you consider the possibility of special characters. Although, it is possible.

Also, I don't think it's the <HyperlinkDestKey:5> tag that's targeting the position of characters, I think it's the <HyperlinkDestIndex:55555> tag.

It might not be ideal, but you could apply a Javascript after importing the tagged text instead of trying to do add your cross-references before hand within the InDesign tagged text. The Javascript API would be a lot easier to work with for cross-references, but it would also be slower.

Here's an example of using hyperlinks with the Javascript API:

// Get the currently active document
var doc = app.activeDocument;

// Get the hyperlink source and destinations by feeding them 
// an InDesign text object.
var linkSource = doc.hyperlinkTextSources.add(sourceText);
var linkDest = doc.textDestinations.add(destText);

// Add the hyperlink to the document
doc.hyperlinks.add(linkSource, linkDest);

You can get the sourceText and destText by finding them within your document. One way to find the text objects that you would like to make into hyperlinks would be to find them using InDesign's find change functionality which is accesible from the DOM.

Josh Voigts
  • 4,114
  • 1
  • 18
  • 43
  • Thank you Josh for the comments and suggestion. My next question is do you have any idea on how I would start doing the the InDesign javascript. I have little knowledge javascript, but not as good as javascripters do. There's is also a script created by JongWare footnote to end note, but this is different from problem since I need to fixed only the links of my cross-ref. Hope you could give me sample script where I should start. Thanks again! – rhemb Dec 03 '12 at 02:11
  • There are some great resources for learning the javascript API. [This](http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products/indesign/pdfs/InDesignCS5_ScriptingGuide_JS.pdf) document from Adobe is the javascripting guide. Also, jongware offers a great set of html docs of the scripting DOM [here](http://jongware.mit.edu/idcs5/inxx.html) – Josh Voigts Dec 07 '12 at 02:35