简体   繁体   中英

XSLT How to iterate a Java List with XALAN

I am trying to iterate over an array using XSLT in order to get a final text looking like this:

array1.firstElement

array1.secondElement

I have this in my XSLT:

<xsl:param name="nombreEmpresaDebe" />

And I put this in my transform method:

transformer.setParameter("nombreEmpresaDebe", listaNombreEmpresaDebe);

renglones/reglon is the name of my node and I am already iterating over it with the following code:

<xsl:for-each select='renglones/renglon'>
    <label>
        <xsl:value-of select="rubro" />
    </label>

    <label>
        <xsl:value-of select="$nombreEmpresaDebe"/>
    </label>
<xsl:for-each>

Now I have to get $nombreEmpresaDebe elements which is a java.util.List but I have no clue about doing it in the same for-each. Does anyone know how to do it?

I need something like this:

 <renglon1>
    <rubro>rubro1</rubro>
    <nombreEmpresaDebe>firstElement</nombreEmpresaDebe>
 </renglon1>
 <renglon2>
    <rubro>rubro2</rubro>
    <nombreEmpresaDebe>secondElement</nombreEmpresaDebe>
 </renglon2>

You can accomplish this by calling a recursive template. For example

<xsl:call-template name="outputList">
    <xsl:with-param name="list" select="$nombreEmpresaDebe"/>
    <xsl:with-param name="index" select="0"/>
</xsl:call-template>

Where the template is defined like

<xsl:template name="outputList">
    <xsl:param name="list"/>
    <xsl:param name="index"/>
        
    <xsl:if test="number($index) &lt; java:size($list)">
         <label>
             <xsl:value-of select="$nombreEmpresaDebe"/>
         </label>
         <xsl:call-template name="outputList">
             <xsl:with-param name="list" select="$list"/>
             <xsl:with-param name="index" select="number($index)+1"/>
         </xsl:call-template>
     </xsl:if>
</xsl:template>

I should note that my answer does not combine this with the iteration of the other nodelist you are handling, but this is the basic List iterating technique that could be combined with that. Also, I realize this is 3 years late, but someone else my find this question and benefit from having an answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM