xml - XSLT-FO for 每个

标签 xml apache xslt apache-fop

这是我的 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 元素?

最佳答案

根据您的更新:由于显然您没有为 Locations 元素添加代码,因此您可以通过更改来缩短代码:

<xsl:apply-templates select="Locations"/>

至:

<xsl:apply-templates select="Locations/LocName"/>

然后做:

<xsl:template match="LocName"> 
    <fo:block text-align="left" font-family="Arial"> 
        <fo:inline font-weight="bold">
            <xsl:value-of select="."/>
        </fo:inline> 
    </fo:block> 
</xsl:template>

关于xml - XSLT-FO for 每个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43651405/

相关文章:

java - 在 Apache Camel 中使用相同的 url 但不同的 http 方法发出 REST 请求时没有响应

xslt - SpecFlow 的自定义报告

xml - 在 grails 中 pretty-print XML 响应的最佳方式

从 PDF 中读取附加的 XML

javascript - 如何在服务器上以SPA模式正确部署Nuxt.js?

apache - 子域重定向到 www

xml - XSLT 在同一级别的其他标签内移动项目

xml - 在 xslt 中添加前导零记录

xml - 为什么 &lt;!DOCTYPE> 在 XML 中是强制性的?

android - 使用 AccessibilityService 读取通知