我可以在XSL-FO块的src属性内包含变量吗?

问题描述 投票:0回答:1

我们要包含60多个图像,并希望使用src属性中的变量名称将其插入到文档中。这是当前不起作用的代码:

没有XSL:-

<var name="Request.Data.Communication.AddressStructured.Sender.OrgId" type="string" />

<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" xmlns:svg="http://www.w3.org/2000/svg" xmlns:th="http://www.thunderhead.com/XSL/Extensions" font-family="Frutiger 45 Light">
  <fo:external-graphic content-height="30mm" content-width="100mm" src="cms:///Resources/Images/Request.Data.Communication.AddressStructured.Sender.OrgId.jpg" />

</fo:block>

使用XSL:-

<xsl:block xmlns:xsl="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" xmlns:svg="http://www.w3.org/2000/svg" 
<xsl:var name="Request.Data.Communication.AddressStructured.Sender.OrgId" select="Request.Data.Communication.AddressStructured.Sender.OrgId"/>

<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Transform" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" xmlns:svg="http://www.w3.org/2000/svg" <fo:external-graphic content-height="30mm" content-width="100mm" src="cms:///Resources/Images/${Request.Data.Communication.AddressStructured.Sender.OrgId}.jpg" />

</fo:block>
</xsl:block>
xslt xsl-fo
1个回答
1
投票

您可能想要{$Request.Data.Communication.AddressStructured.Sender.OrgId}而不是${Request.Data.Communication.AddressStructured.Sender.OrgId},否则请继续阅读...


从源XML到PDF输出是一个两步过程(除非您直接在XSL-FO词汇表中编写文档)。步骤是:

  1. XSLT转换将您的XML转换为XSL Formatter理解的XSL-FO词汇表中的XML
  2. [XSL Formatter对XSL-FO进行格式化以制作页面并将这些页面输出为PDF,SVG等。

此图来自XSL 1.1建议书(https://www.w3.org/TR/xsl11/#d0e147)试图说明该过程:

XSL involves transformation followed by formatting

XSLT阶段具有变量,但是XSL-FO阶段没有变量。 (您可以为(大多数)XSL-FO属性的值编写表达式,但是表达式语言(请参见https://www.w3.org/TR/xsl11/#d0e5032)不会扩展为具有变量。)

因此,在您的XSLT样式表中,您将得到类似以下内容:

{$Request.Data.Communication.AddressStructured.Sender.OrgId}.jpg

其中:

  • $Request.Data.Communication.AddressStructured.Sender.OrgId是变量(或参数)引用。没有足够的信息来知道您如何定义变量。
  • [{...}是属性值模板(AVT),当您要评估表达式以生成部分或全部属性值时使用。

XSLT阶段的输出将包含评估表达式所得的文字字符串,并且XSL Formatter将使用实际的URL来正确定位图像。

© www.soinside.com 2019 - 2024. All rights reserved.