我可以在 XSL-FO 块的 src 属性中包含一个变量吗?
Can I include a variable inside a src attribute of an XSL-FO block?
我们有 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>
您可能需要 {$Request.Data.Communication.AddressStructured.Sender.OrgId}
而不是 ${Request.Data.Communication.AddressStructured.Sender.OrgId}
,否则继续阅读...
从您的来源 XML 到 PDF 输出是一个两步过程(除非您直接在 XSL-FO 词汇表中创作文档)。步骤是:
- XSLT 转换将您的 XML 转换为 XSL 格式化程序理解的 XSL-FO 词汇表中的 XML
- XSL 格式化程序格式化 XSL-FO 以制作页面并将这些页面输出为 PDF、SVG 等
来自 XSL 1.1 Recommendation (https://www.w3.org/TR/xsl11/#d0e147) 的这张图试图说明该过程:
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 格式化程序将使用实际的 URL 来正确定位图像。
我们有 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>
您可能需要 {$Request.Data.Communication.AddressStructured.Sender.OrgId}
而不是 ${Request.Data.Communication.AddressStructured.Sender.OrgId}
,否则继续阅读...
从您的来源 XML 到 PDF 输出是一个两步过程(除非您直接在 XSL-FO 词汇表中创作文档)。步骤是:
- XSLT 转换将您的 XML 转换为 XSL 格式化程序理解的 XSL-FO 词汇表中的 XML
- XSL 格式化程序格式化 XSL-FO 以制作页面并将这些页面输出为 PDF、SVG 等
来自 XSL 1.1 Recommendation (https://www.w3.org/TR/xsl11/#d0e147) 的这张图试图说明该过程:
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 格式化程序将使用实际的 URL 来正确定位图像。