i new xsl-fo , xpath , have difficult in achieving following requirement. requirement results below xml , xsl-fo:
i need show results below
line# item description quantity line_arrival_date 1 test po print-1 15 30-aug-2016 2 test po print-2 25 30-sep-2016
as see line #
, item description
, quantity
come po_data/lines/lines_row/
information , line_arrival_date
comes po_data/purchaseorder/line_ref/po_line_type
, way related po_line_id
in lines_row
, po_line_type
xml parents.
thought having 2 for-each not helping , not able for-each xsl-fo (below) , maybe lack of knowledge on xsl-fo constraint. please let me know if can achieve requirement , of how achieve this.
thanks looking.
<po_data> <segment1>321178</segment1> <lines> <lines_row> <line_num>1</line_num> <item_description>test po print-1</item_description> <cancel_flag>n</cancel_flag> <unit_meas_lookup_code>each</unit_meas_lookup_code> <order_type_lookup_code>quantity</order_type_lookup_code> <unit_price>25</unit_price> <quantity>15</quantity> <po_header_id>408363</po_header_id> <po_line_id>697709</po_line_id> </lines_row> <lines_row> <line_num>2</line_num> <item_description>test po print-2</item_description> <cancel_flag>n</cancel_flag> <unit_meas_lookup_code>each</unit_meas_lookup_code> <order_type_lookup_code>quantity</order_type_lookup_code> <unit_price>25</unit_price> <quantity>15</quantity> <po_header_id>408363</po_header_id> <po_line_id>697710</po_line_id> </lines_row> </lines> <purchaseorder> <po_header_id>408363</po_header_id> <line_ref> <poline_typ> <po_line_id>697709</po_line_id> <line_arrival_date>30-aug-2016</line_arrival_date> </poline_typ> <poline_typ> <po_line_id>697710</po_line_id> <line_arrival_date>30-sep-2016</line_arrival_date> </poline_typ> </line_ref> </purchaseorder> </po_data>
<xsl:template match="/"> <html> <body> <h2>my po lines</h2> <table border="1"> <tr bgcolor="#9acd32"> <th style="text-align:left">line #</th> <th style="text-align:left">item description</th> <th style="text-align:left">spolineid</th> <th style="text-align:left">cpolineid</th> <th style="text-align:left">comparison</th> </tr> <xsl:for-each select="po_data/lines/lines_row"> <!--xsl:for-each select="purchaseorder/line_ref"--> <!--xsl:for-each select="purchaseorder/line_ref/poline_typ"--> <tr> <td><xsl:value-of select="line_num"/></td> <td><xsl:value-of select="item_description"/></td> <!--xsl:variable name="spolineid" select="string(po_line_id)"/> <td><xsl:value-of select="$spolineid" /></td> <xsl:variable name="cpolineid" select="string(../../purchaseorder/line_ref/poline_typ/po_line_id)"/> <td><xsl:value-of select="$cpolineid" /></td> <td><xsl:if test = "$spolineid = $cpolineid "> <xsl:value-of select="../../purchaseorder/line_ref/poline_typ/line_arrival_date"/></xsl:if></td--> <td><xsl:for-each select="po_data/purchaseorder/line_ref/poline_typ"> <xsl:value-of select="line_arrival_date"/> </xsl:for-each></td> </tr> </xsl:for-each> <!--/xsl:for-each--> </table> </body> </html> </xsl:template> </xsl:stylesheet>
following stylesheet work if using xslt 1.0 processor:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:template match="/"> <html> <body> <h2>my po lines</h2> <table border="1"> <tr bgcolor="#9acd32"> <th style="text-align:left">line #</th> <th style="text-align:left">item description</th> <th style="text-align:left">quantity</th> <th style="text-align:left">line_arrival_date</th> </tr> <xsl:for-each select="po_data/lines/lines_row"> <tr> <td><xsl:value-of select="line_num"/></td> <td><xsl:value-of select="item_description"/></td> <td><xsl:value-of select="quantity"/></td> <td> <xsl:value-of select="(/po_data/purchaseorder/line_ref/poline_typ[string(po_line_id) = string(current()/po_line_id)]/line_arrival_date)[1]"/> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
for reference added more elegant xsl:key , key() solution:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:key name="line" match="/po_data/purchaseorder/line_ref/poline_typ" use="po_line_id"/> <xsl:template match="/"> <html> <body> <h2>my po lines</h2> <table border="1"> <tr bgcolor="#9acd32"> <th style="text-align:left">line #</th> <th style="text-align:left">item description</th> <th style="text-align:left">quantity</th> <th style="text-align:left">line_arrival_date</th> </tr> <xsl:for-each select="po_data/lines/lines_row"> <tr> <td><xsl:value-of select="line_num"/></td> <td><xsl:value-of select="item_description"/></td> <td><xsl:value-of select="quantity"/></td> <td> <xsl:value-of select="(key('line',po_line_id)/line_arrival_date)[1]"/> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
above 2 xslt stylesheets tested via xslt 1.0 processor saxon 6.5.5 , msxml.
Comments
Post a Comment