【发布时间】:2017-04-27 07:35:39
【问题描述】:
这是我的 xml:
<OrdersSchedulePDFView>
<OrdersSchedulePDFViewRow>
<Locations>
<LocName>Text1</LocName>
<LocName>Text2</LocName>
</Locations>
</OrdersSchedulePDFViewRow>
</OrdersSchedulePDFView>
这是我的 xslt-fo 文件中的片段:
<xsl:template match="OrdersSchedulePDFView">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:for-each select="./OrdersSchedulePDFViewRow">
<fo:page-sequence master-reference="all">
<fo:flow flow-name="xsl-region-body">
<xsl:for-each select="Locations">
<xsl:apply-templates select="."/>
</xsl:for-each>
</fo:flow>
</fo:page-sequence>
</xsl:for-each>
</fo:root>
</xsl:template>
<xsl:template match="Locations">
<fo:block text-align="left" font-family="Arial">
<fo:inline font-weight="bold"><xsl:value-of select="LocName"/></fo:inline>
</fo:block>
</xsl:template>
</xsl:stylesheet>
但在 PDF 中,我只有一个 LocName。如何获取所有 LocName 元素?
【问题讨论】:
-
<xsl:value-of select="LocName"/>仅获取第一个LocName的值(在 XSLT 1.0 中)。要获得所有这些,您需要使用<xsl:for-each select="LocName">。或者对它们应用模板,并添加相应的模板。 --- 顺便说一句,您确实不需要需要使用<xsl:for-each select="Locations">才能应用匹配Locations的模板。只需说<xsl:apply-templates select="Locations"/>。 -
最后,我想通了。
标签: xml apache xslt apache-fop