如果目录XSLT 1.0不存在@id,则为元素的generate-id()

时间:2017-03-11 02:07:30

标签: xml xslt xsl-fo

假设:

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

1 个答案:

答案 0 :(得分:0)

test="not[@id]"

测试是否存在具有<not>属性的元素id。你想要

test="not(@id)"