title: Indesign Tagged text cross-reference that works like cross-reference using ICML tags
body: <p>I've looking for solution on how to create cross-reference using InDesign Tagged Text but I can't find any good suggestion.</p>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>Below is my XSLT codes to create cross-ref for Tagged Text:</p>
  
  <p><strong>Adding Cross-ref to InDesign:</strong></p>
  
  <pre><code>&lt;xsl:template match="/"&gt;
      &lt;--! End Notes --&gt;
      &lt;xsl:text&gt;&amp;#60;XRefFmtDefn:=&amp;#60;FmtNm:ntf&gt;&amp;#60;CharStyleRef:ntf&gt;&amp;#60;BldBlkLen:1&gt;&amp;#60;BldBlk:=&amp;#60;BlkTyp:ParagraphNumber&gt;&amp;#60;CstmTxt:&gt;&amp;#60;CharStyleRef:&gt;&amp;#60;InclDlm:0&gt;&gt;&gt;&lt;/xsl:text&gt;
      &lt;xsl:for-each select="descendant::apnf"&gt;
          &lt;xsl:variable name="num" select="count(preceding::apnf) + 1"/&gt;
          &lt;xsl:text&gt;&amp;#60;HplDestDfn:=&amp;#60;HplDestName:Anchor &lt;/xsl:text&gt;&lt;xsl:value-of select="$num"/&gt;&lt;xsl:text&gt;&gt;&amp;#60;DestKey:&lt;/xsl:text&gt;&lt;xsl:value-of select="$num"/&gt;&lt;xsl:text&gt;&gt;&amp;#60;HplDestIdx:1&lt;/xsl:text&gt;&lt;xsl:text&gt;&gt;&amp;#60;IsPara:1&gt;&amp;#60;Hid:0&gt;&gt;&lt;/xsl:text&gt;
      &lt;/xsl:for-each&gt;
  
      &lt;--! URL --&gt;
  
      &lt;xsl:text disable-output-escaping="yes"&gt;&amp;#60;HplDestDfn:=&lt;/xsl:text&gt;
      &lt;xsl:for-each select="descendant::libelle[generate-id()=generate-id(key('urlDistinct', @cible)[1])]"&gt;
          &lt;xsl:value-of select="concat('&amp;#60;HplDestName:', replace(@cible,'/', '\\/'),'&amp;#62;&amp;#60;DestKey:1&amp;#62;&amp;#60;HplDestUrl:http\:\/\/', replace(@cible,'/', '\\/'), '&amp;#62;')"/&gt;
      &lt;/xsl:for-each&gt;
      &lt;xsl:text disable-output-escaping="yes"&gt;&amp;#60;Hid:0&amp;#62;&amp;#62;&lt;/xsl:text&gt;
      &lt;xsl:apply-templates/&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p><strong>Create cross-ref links for End Notes:</strong></p>
  
  <pre><code>&lt;xsl:template match="apnf"&gt;
      &lt;xsl:variable name="num" select="count(preceding::apnf) + 1"/&gt;
      &lt;xsl:text&gt;&amp;#60;cstyle:ntf&amp;#62;&lt;/xsl:text&gt;
      &lt;xsl:text&gt;&amp;lt;Hpl:=&amp;lt;HplName:&lt;/xsl:text&gt;&lt;xsl:value-of select="@id"/&gt; &lt;xsl:text&gt;&gt;&amp;lt;HplDest:Anchor &lt;/xsl:text&gt;&lt;xsl:value-of select="$num"/&gt;&lt;xsl:text&gt;&gt;&amp;lt;DestKey:&lt;/xsl:text&gt;&lt;xsl:value-of select="$num"/&gt;&lt;xsl:text&gt;&gt;&amp;lt;XRefFmt:ntf&gt;&amp;lt;CharStyleRef:&gt;&amp;lt;HplLen:1&gt;&amp;lt;HplOff:0&gt;&amp;lt;Hid:0&gt;&amp;lt;Brdrv:0&gt;&amp;lt;Brdrw:Thin&gt;&amp;lt;Brdrh:None&gt;&amp;lt;Brdrs:Solid&gt;&amp;lt;Brdrc:0\,0\,0&gt;&gt;&lt;/xsl:text&gt;
      &lt;xsl:value-of select="$num"/&gt;
      &lt;xsl:text&gt;&amp;#60;cstyle:&amp;#62;&lt;/xsl:text&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p><strong>Create cross-ref URLs</strong></p>
  
  <pre><code>&lt;xsl:template match="url"&gt;
      &lt;xsl:text&gt;&amp;#60;cstyle:url&amp;#62;&lt;/xsl:text&gt;
      &lt;xsl:choose&gt;
          &lt;xsl:when test="exists(libelle)"&gt;
              &lt;xsl:text&gt;&amp;lt;Hpl:=&amp;lt;HplName:&lt;/xsl:text&gt;&lt;xsl:value-of select="replace(libelle/@cible,'/', '\\/')"/&gt;&lt;xsl:text&gt;&amp;gt;&amp;lt;HplDest:http\:\/\/&lt;/xsl:text&gt;&lt;xsl:value-of select="replace(libelle/@cible,'/', '\\/')"/&gt;&lt;xsl:text&gt;&gt;&amp;lt;DestKey:1&gt;&amp;lt;CharStyleRef:&gt;&amp;lt;HplLen:3&gt;&amp;lt;HplOff:0&gt;&amp;lt;Hid:0&gt;&amp;lt;Brdrv:0&gt;&amp;lt;Brdrw:Thin&gt;&amp;lt;Brdrh:None&gt;&amp;lt;Brdrs:Solid&gt;&amp;lt;Brdrc:0\,0\,0&gt;&gt;&lt;/xsl:text&gt;
              &lt;xsl:sequence select="libelle/text()"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
              &lt;xsl:sequence select="./text()"/&gt;
          &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
      &lt;xsl:text&gt;&amp;#60;cstyle:&amp;#62;&lt;/xsl:text&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p><strong>My questions are:</strong></p>
  
  <ol>
  <li>Cross-Reference is supported in InDesign Tagged Text like ICML does?</li>
  <li>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.</li>
  </ol>
  
  <p>Any suggestions or recommendations is highly appreciated.</p>
  
  <p>Thanks!</p>
  
  <p>P.S. This link <a href="http://forums.adobe.com/message/3978432#3978432" rel="nofollow">http://forums.adobe.com/message/3978432#3978432</a> also discussed InDesign Tagged Text for Cross-reference Entries but there is no complete solution is given.</p>