<fo:basic-link>没有创建可点击的链接XSL-FO XSLT 1.0

时间:2016-08-24 14:52:58

标签: xslt hyperlink xsl-fo

鉴于此XML:

<figure id="fig-0011">
<title>Removal of Shipping Kit(s)</title>
<graphic id="fig-0011-gra-0001" infoEntityIdent="66503-00129-A-001-01"></graphic>
</figure>

<proceduralStep><para>Remove screw (see <internalRef internalRefId="fig-0011" internalRefTargetType="irtt01"></internalRef>) 
<proceduralStep><para>Remove two screws (10) (see <internalRef internalRefId="fig-0011-gra-0001" internalRefTargetType="irtt09"></internalRef>),

我正在尝试创建图形和图形的链接。图的链接工作正常,但图形的链接不是:

<fo:basic-link>
<xsl:attribute name="internal-destination"><xsl:apply-templates select="//dmodule/identAndStatusSection/dmAddress/dmIdent/dmCode"/><xsl:value-of select="@internalRefId"/></xsl:attribute>
<xsl:variable name="targetElement" select="local-name(key('id',@internalRefId))"/>
<xsl:for-each select="key('id',(@internalRefId))">
    <xsl:choose>
        <xsl:when test="$targetElement='graphic'">
            <xsl:text>Fig </xsl:text>
            <xsl:number count="figure" from="content" level="any"/>
        </xsl:when>
        <xsl:when test="$targetElement='figure'">
            <xsl:text>Fig </xsl:text>
            <xsl:number count="figure" from="content" level="any"/>
        </xsl:when>
    </xsl:choose>
</xsl:for-each>

键:

<xsl:key name="id" match="*" use="@id"/>

图:

<xsl:template match="figure">
    <xsl:apply-templates select="graphic"/>     
</xsl:template>

<xsl:template match="figure/graphic" priority="10">
    <fo:block text-align="center" start-indent="0pt" color="black" keep-with-next="always">
        <xsl:call-template name="do-graphic">
            <xsl:with-param name="include-graphic" select="true()"/>
        </xsl:call-template>
    </fo:block>
    <xsl:if test="position()=last()">
        <xsl:apply-templates select="../legend"/>
    </xsl:if>
    <xsl:if test="@infoEntityIdent">
        <fo:block text-align="right" keep-with-previous="always">
            <xsl:value-of select="@infoEntityIdent"/>
        </fo:block>
    </xsl:if>
    <fo:block font-weight="normal" font-style="italic" text-align="center" space-before="12pt" space-after="8pt" start-indent="0pt" keep-with-previous="always">
        <xsl:if test="../@id">
            <xsl:attribute name="id"><xsl:apply-templates select="//dmodule/identAndStatusSection/dmAddress/dmIdent/dmCode"/><xsl:value-of select="../@id"/></xsl:attribute>
        </xsl:if>
        <xsl:text>Fig  </xsl:text>
        <xsl:number count="figure" level="any" format="1" from="content"/>
        <xsl:apply-templates select="../title"/>
        <xsl:variable name="numSheets" select="count(../graphic)"/>
        <xsl:choose>
            <xsl:when test="$numSheets>1">
                <xsl:text> (Sheet </xsl:text>
                <xsl:number count="graphic" level="any" format="1" from="figure"/>
                <xsl:text> of </xsl:text>
                <xsl:value-of select="$numSheets"/>
                <xsl:text>)</xsl:text>
            </xsl:when>
        </xsl:choose>
    </fo:block>

图形:

<xsl:template match="graphic">
    <fo:inline-container>
        <fo:block space-before="12pt" space-before.conditionality="retain">
            <xsl:call-template name="do-graphic"/>
        </fo:block>
    </fo:inline-container>
</xsl:template>

<xsl:template name="do-graphic">
    <xsl:param name="include-graphic" select="true()"/>
    <xsl:variable name="content-width">
        <xsl:choose>
            <xsl:when test="@reproductionWidth != ''">
                <xsl:value-of select="@reproductionWidth"/>
            </xsl:when>
            <!-- coding for reproduction scale based on clarifications in Issue 4.1 -->
            <xsl:when test="@reproductionScale != ''">
                <xsl:value-of select="@reproductionScale"/>
                <xsl:text>%</xsl:text>
            </xsl:when>
            <xsl:otherwise>95%</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="content-height">
        <xsl:choose>
            <xsl:when test="@reproductionHeight != ''">
                <xsl:value-of select="@reproductionHeight"/>
            </xsl:when>
            <xsl:when test="@reproductionScale != ''">
            <xsl:value-of select="@reproductionScale"/>
                <xsl:text>%</xsl:text>
            </xsl:when>
            <xsl:otherwise>95%</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:choose>
        <xsl:when test="$include-graphic">
            <fo:external-graphic src="{unparsed-entity-uri(@infoEntityIdent)}" scaling="uniform" content-height="{$content-height}" content-width="{$content-width}"/>
        </xsl:when>
        <xsl:otherwise>
            <fo:inline-container display-align="center" text-align="center" block-progression-dimension="{$content-height}" inline-progression-dimension="{$content-width}" background-color="silver" color="red">
                <fo:block>Graphic Not Included</fo:block>
            </fo:inline-container>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

返回:

    Remove two screws (10) (see Fig 2) 

这是正确的图号,但2不是图形的可点击链接。

dmcode模板构建一个字符串。如果我从XSLT中删除它,那么图号不再链接到该图。

我正在使用XSLT 1.0。感谢您的帮助,谢谢。

2 个答案:

答案 0 :(得分:0)

第二个internalRef指的是graphic。您的XSLT似乎没有将graphic/@id复制到结果树中的FO中。使用AH Formatter和不复制graphic/@id的样式表,我得不到任何链接和错误消息:

Unresolved internal-destination: "fig-0011-gra-0001".

当没有匹配的目标ID时,您的FO格式化程序似乎也没有建立链接。

如果没有看到xsl:key声明,figuregraphic的模板,并且知道graphic是否可以在外面展示,我就无法帮助您figure

已重新使用figure/@idgraphic/@id

<xsl:key name="id" match="*" use="@id" />

<xsl:variable name="prefix">
    <xsl:apply-templates select="//dmodule/identAndStatusSection/dmAddress/dmIdent/dmCode" />
</xsl:variable>

<xsl:template match="internalRef">
    <xsl:for-each select="key('id', @internalRefId)">
        <fo:basic-link internal-destination="{$prefix}{@id}">
            <xsl:text>Fig </xsl:text>
            <xsl:number count="figure" from="content" level="any" />
        </fo:basic-link>
    </xsl:for-each>
</xsl:template>

<xsl:template match="figure">
    <fo:wrapper id="{@id}">
        <xsl:apply-templates select="graphic" />
    </fo:wrapper>     
</xsl:template>

<xsl:template match="figure/graphic" priority="10">
    <fo:block text-align="center" start-indent="0pt" color="black" keep-with-next="always">
        <xsl:if test="@id">
            <xsl:attribute name="id">
                <xsl:value-of select="$prefix" />
                <xsl:value-of select="@id" />
            </xsl:attribute>
        </xsl:if>
        <xsl:call-template name="do-graphic">
            <xsl:with-param name="include-graphic" select="true()" />
        </xsl:call-template>
    </fo:block>
    <xsl:if test="position() = last()">
        <xsl:apply-templates select="../legend" />
    </xsl:if>
    <xsl:if test="@infoEntityIdent">
        <fo:block text-align="right" keep-with-previous="always">
            <xsl:value-of select="@infoEntityIdent" />
        </fo:block>
    </xsl:if>
    <fo:block font-weight="normal" font-style="italic" text-align="center" space-before="12pt" space-after="8pt" start-indent="0pt" keep-with-previous="always">
        <xsl:text>Fig  </xsl:text>
        <xsl:number count="figure" level="any" format="1" from="content" />
        <xsl:apply-templates select="../title" />
        <xsl:variable name="numSheets" select="count(../graphic)" />
        <xsl:choose>
            <xsl:when test="$numSheets > 1">
                <xsl:text> (Sheet </xsl:text>
                <xsl:number count="graphic" level="any" format="1" from="figure" />
                <xsl:text> of </xsl:text>
                <xsl:value-of select="$numSheets" />
                <xsl:text>)</xsl:text>
            </xsl:when>
        </xsl:choose>
    </fo:block>
</xsl:template>

我还将图片的ID移到了fo:block模板中的第一个figure/graphic。将它放在最后fo:block上意味着每次跟踪到图形的链接时都会向上滚动以查看图形。

答案 1 :(得分:0)

有人建议将<xsl:attribute name="id">添加到do-graphic模板中的<fo:external-graphic>,这似乎可以解决问题:

<xsl:template name="do-graphic">
    <xsl:param name="include-graphic" select="true()"/>
    <xsl:variable name="content-width">
        <xsl:choose>
            <xsl:when test="@reproductionWidth != ''">
                <xsl:value-of select="@reproductionWidth"/>
                <xsl:call-template name="checkForUom">
                    <xsl:with-param name="measure" select="@reproductionWidth"/>
                </xsl:call-template>
            </xsl:when>
            <!-- coding for reproduction scale based on clarifications in Issue 4.1 -->
            <xsl:when test="@reproductionScale != ''">
                <xsl:value-of select="@reproductionScale"/>
                <xsl:text>%</xsl:text>
            </xsl:when>
            <xsl:otherwise>95%</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="content-height">
        <xsl:choose>
            <xsl:when test="@reproductionHeight != ''">
                <xsl:value-of select="@reproductionHeight"/>
                <xsl:call-template name="checkForUom">
                    <xsl:with-param name="measure" select="@reproductionWidth"/>
                </xsl:call-template>
            </xsl:when>
            <!-- coding for reproduction scale based on clarifications in Issue 4.1 -->
            <xsl:when test="@reproductionScale != ''">
                <xsl:value-of select="@reproductionScale"/>
                <xsl:text>%</xsl:text>
            </xsl:when>
            <xsl:otherwise>95%</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:choose>
        <xsl:when test="$include-graphic">
            <fo:external-graphic src="{unparsed-entity-uri(@infoEntityIdent)}" scaling="uniform" content-height="{$content-height}" content-width="{$content-width}">
            <xsl:attribute name="id"><xsl:apply-templates select="//dmodule/identAndStatusSection/dmAddress/dmIdent/dmCode"/><xsl:value-of select="@id"/></xsl:attribute>
            </fo:external-graphic>
        </xsl:when>
        <xsl:otherwise>
            <fo:inline-container display-align="center" text-align="center" block-progression-dimension="{$content-height}" inline-progression-dimension="{$content-width}" background-color="silver" color="red">
                <fo:block>Graphic Not Included</fo:block>
            </fo:inline-container>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>