Search code examples
xmlapachexsltapache-fop

XSLT-FO for-each


This is my xml:

<OrdersSchedulePDFView>
 <OrdersSchedulePDFViewRow>
   <Locations>
     <LocName>Text1</LocName>
     <LocName>Text2</LocName>         
   </Locations>
 </OrdersSchedulePDFViewRow>     
</OrdersSchedulePDFView>

And this is fragment from my xslt-fo file:

<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>

But in PDF I have only one LocName. How can I get all LocName elements?


Solution

  • Based on your update: since apparently you have no code to add for a Locations element, you could shorten your code by changing:

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

    to:

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

    and then doing:

    <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>