Indesign标记文本交叉引用,其作用类似于使用ICML标记的交叉引用

时间:2012-11-29 04:00:37

标签: xslt-2.0 adobe-indesign

我正在寻找有关如何使用InDesign标记文字创建交叉引用的解决方案,但我找不到任何好的建议。

这是我的方案我的任务是创建XML到InDesign的圆形跳闸工作流程和InDesign到XML,反之亦然。我还需要对URL和End Notes链接进行交叉引用。

首先,我必须创建和XSLT脚本,将XML转换为InDesign标记文本(我使用标记文本,因为我们的大多数操作员仍在使用InDesign CS3)。然后在页面组合完成后,我们必须将InDesign文件导出到XHTML(导出为Dreamweaver)。创建另一个XSLT脚本以将XHTML转换回XML以用于ePub转换(为什么不直接将InDesign导出到ePub?答案是需要进行大量自定义)。

以下是我为标记文本创建交叉引用的XSLT代码:

将交叉引用添加到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>

为结束备注创建交叉引用链接:

<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>

创建交叉引用网址

<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>

这是我的问题,当我将标记文本导入InDesign URL并且endnotes具有死链接时。我怀疑它是目标密钥,因为当我尝试使用工作链接导出示例InDesign时,目标密钥的目标是字符的位置,它应该交叉引用。

我的问题是:

  1. InDesign标记文本支持交叉引用,如ICML吗?
  2. 我是否可以使用XSLT获取XML中字符的位置()(意味着整个XML中的字符位置不在单个节点内)?如果可能,我可以正确地获得目的地密钥。
  3. 非常感谢任何建议或建议。

    谢谢!

    P.S。此链接http://forums.adobe.com/message/3978432#3978432还讨论了针对交叉引用条目的InDesign标记文本,但没有给出完整的解决方案。

1 个答案:

答案 0 :(得分:1)

刚为自己测试了这个。可以在导入之前添加对标记文本的交叉引用,但是如您所述,您必须找到交叉引用目标与整个文档相比的字符位置。这听起来很难并且容易出错,尤其是当您考虑特殊字符的可能性时。虽然,但这是可能的。

此外,我认为这不是<HyperlinkDestKey:5>标记定位字符的位置,我认为它是<HyperlinkDestIndex:55555>标记。

这可能不太理想,但您可以在导入标记文本后应用Javascript,而不是尝试在InDesign标记文本中添加交叉引用。对于交叉引用,Javascript API将更容易使用,但它也会更慢。

以下是使用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);

您可以在文档中找到sourceTextdestText。找到您想要制作超链接的文本对象的一种方法是使用InDesign的查找更改功能来查找它们,这些功能可以从DOM访问。