mercredi 21 mai 2014

Créer quelques tables .xslt bouclage throught .xml - Stack Overflow


I'm trying to loop throught an .xml to create different tables getting few attributes from .xml. When I try to show only one table it's ok, but I want to make a new table for each new date.


The .xml structure is like this:


  <root>
<doc>
<RES_DATE>
<LIS_RES_DATE
data_res="23/01/2009"
convo="AE"
letter="null"
...
/>
<LIS_RES_DATE
date_res="02/02/2009"
...
/>
</RES_DATE>
</doc>
</root>

I've created 3 xsl:template. One to create tables, and this one calls that one who create the header and that one who create the body.


The code belows is the body maker:


<xsl:template name="bodier">
<xsl:for-each select="/root/doc/RES_DATE/LIS_RES_DATE[@data_res='23/01/2009']">
<!-- ROW 1 -->
<fo:table-row>
<fo:table-cell>
<fo:block>
<xsl:value-of select='@convo'/>
</fo:block>
</fo:table-cell>

<!-- few table-cells getting attributes -->

</fo:table-row>
</xsl:for-each>
</xsl:template>

So, if I can change the value of @data_res in the body maker I could make it possible, but, how?


EDIT: At least! I resolved it. The key is on the calling to the template that creates the tables, so, we shall insert it into a for-each and then define 2 conditions. Just like this:


<xsl:for-each select="../RES_DATE/LIS_RES_DATE">
<xsl:if test="@data_res!=following-sibling::LIS_RES_DATE[1]/@data_res or @convo=following-sibling::LIS_RES_DATE[1]/@convo">

And then call the template with params res_date and convo.


Works perfectly!



I'm trying to loop throught an .xml to create different tables getting few attributes from .xml. When I try to show only one table it's ok, but I want to make a new table for each new date.


The .xml structure is like this:


  <root>
<doc>
<RES_DATE>
<LIS_RES_DATE
data_res="23/01/2009"
convo="AE"
letter="null"
...
/>
<LIS_RES_DATE
date_res="02/02/2009"
...
/>
</RES_DATE>
</doc>
</root>

I've created 3 xsl:template. One to create tables, and this one calls that one who create the header and that one who create the body.


The code belows is the body maker:


<xsl:template name="bodier">
<xsl:for-each select="/root/doc/RES_DATE/LIS_RES_DATE[@data_res='23/01/2009']">
<!-- ROW 1 -->
<fo:table-row>
<fo:table-cell>
<fo:block>
<xsl:value-of select='@convo'/>
</fo:block>
</fo:table-cell>

<!-- few table-cells getting attributes -->

</fo:table-row>
</xsl:for-each>
</xsl:template>

So, if I can change the value of @data_res in the body maker I could make it possible, but, how?


EDIT: At least! I resolved it. The key is on the calling to the template that creates the tables, so, we shall insert it into a for-each and then define 2 conditions. Just like this:


<xsl:for-each select="../RES_DATE/LIS_RES_DATE">
<xsl:if test="@data_res!=following-sibling::LIS_RES_DATE[1]/@data_res or @convo=following-sibling::LIS_RES_DATE[1]/@convo">

And then call the template with params res_date and convo.


Works perfectly!


0 commentaires:

Enregistrer un commentaire