【问题标题】:generate-id() for element if @id doesn't exist for table of contents XSLT 1.0如果目录 XSLT 1.0 的 @id 不存在,则为元素生成-id()
【发布时间】:2017-03-11 02:07:29
【问题描述】:

给定:

<levelledPara><title>Tools List and Tool Illustrations</title>
<levelledPara><title>General</title>
<levelledPara><para>The special tools, fixtures, and equipment needed.</para></levelledPara>

我需要在我的目录中包含 levelledPara 的第一级标题(所以只会出现“工具列表和工具插图”。)如果 id 没有,我想为第一个 levelledPara 生成一个@id存在,所以我可以将它链接到页码。链接需要 dmcode。它没有像我希望的那样工作,正在生成 id 但页码没有解析。

<xsl:template match="levelledPara" mode="tocdm">
    <xsl:if test="title and not(parent::levelledPara)">
        <xsl:variable name="id">
                <xsl:call-template name="para.id"/>
         </xsl:variable>
         <xsl:attribute name="id">
            <xsl:value-of select="$id"/>
         </xsl:attribute>
    <xsl:variable name="dmcode"><xsl:apply-templates select="ancestor::dmodule/identAndStatusSection/dmAddress/dmIdent/dmCode"/></xsl:variable>
    <xsl:variable name="lpcode"><xsl:value-of select="$dmcode" /><xsl:value-of select="$id"/></xsl:variable>
    <fo:table-row>
        <fo:table-cell xsl:use-attribute-sets="table.cell.padding1" number-columns-spanned="2">
            <fo:block  text-align-last="justify" text-indent="21mm">
                            <xsl:number count="levelledPara" from="content" level="multiple" format="1.1.1.1.1"/>
                            <xsl:text>&#160;&#160; </xsl:text>
                <xsl:value-of select="title" /><fo:leader leader-pattern="dots"/><fo:basic-link><xsl:attribute name="internal-destination"><xsl:value-of select="$lpcode" /></xsl:attribute><fo:page-number-citation ref-id="{$lpcode}"/></fo:basic-link>

            </fo:block> 
        </fo:table-cell>
    </fo:table-row>
    </xsl:if>   
</xsl:template>

<xsl:template name="para.id">
      <xsl:param name="object" select="."/>
  <xsl:choose>
    <xsl:when test="$object/@id">
        <xsl:value-of select="$object/@id"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="generate-id($object)"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

【问题讨论】:

    标签: xml xslt xsl-fo


    【解决方案1】:
    test="not[@id]"
    

    测试是否存在具有id 属性的元素&lt;not&gt;。你想要的

    test="not(@id)"
    

    【讨论】:

    • 谢谢,我做了更改,但链接中仍未生成 id。
    猜你喜欢
    • 2016-02-08
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多