从属性集属性中获取值

Get the value from a attribute set attribute

大家好,我想在我的 pdf 中实现标题结构。不同的headers应该从旧的取值加2mm得到一个结构 我使用 xslt 2.0 和 antenna house

xslt:

<xsl:attribute-set name="head5">
    <xsl:attribute 
           name="distance">2cm</xsl:attribute>
    </xsl:attribute-set>
<xsl:attribute-set name="head6">
    <xsl:attribute 
           name="distance"><xsl:value-of select=""/>
    </xsl:attribute>
</xsl:attribute-set>

假设在您调用属性集时,上下文项是您要修改其@distance 属性的元素,您可以这样做

<xsl:attribute name="distance" select="f:add-mm-to-distance(@distance, 2)"/>

然后你可以写一个像

这样的函数
<xsl:function name="f:add-mm-to-distance" as="xs:string">
  <xsl:param name="in" as="xs:string"/>
  <xsl:param name="add" as="xs:integer"/>
  <xsl:choose>
    <xsl:when test="ends-with($in, 'mm')">
      <xsl:sequence select="concat(number(substring-before($in, 'mm'))+$add, 'mm')"/>
    </xsl:when>
    <xsl:when test= ...

显然,函数的详细信息取决于您希望在@distance 属性中找到的内容。

有很多方法可以做到这一点,但在对示例代码造成最小损害的情况下回答您的问题的方法是将其留给 Antenna House 格式化程序来添加长度:

<!-- Untested. -->
<xsl:attribute-set name="head5">
  <xsl:attribute 
       name="distance">2cm</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="head6">
  <xsl:attribute name="distance">
    <xsl:variable name="dummy" as="element()">
      <dummy xsl:use-attribute-sets="head5" />
    </xsl:variable>
    <xsl:value-of select="$dummy/@distance"/> + 2mm</xsl:attribute>
</xsl:attribute-set>

但是,这是低效的,因为格式化程序每次在 FO 文档中遇到 'distance' 属性(XSL 1.1 中未定义,顺便说一句)时都必须计算表达式。

您可以事先在 XSLT 中进行计算,例如:

<xsl:variable name="distances"
              select="'2cm', '22mm'"
              as="xs:string+" />

<xsl:attribute-set name="head5">
  <xsl:attribute name="distance" select="$distances[1]" />
</xsl:attribute-set>
<xsl:attribute-set name="head6">
  <xsl:attribute name="distance" select="$distances[2]" />
</xsl:attribute-set>

或者,编写一个对长度求和的 XSLT 函数并不难,因此您可以将计算值放入 FO 文档中。