【发布时间】:2020-10-07 11:26:48
【问题描述】:
我有以下xml
<invoice>
<transport-orders type="array">
<transport-order type="Lr">
<number>2663</number>
<consignor-city>Mumbai</consignor-city>
<consignee-city>Bangalore</consignee-city>
</transport-order>
<transport-order type="TripOrder">
<number nil="true"/>
<consignor-city>Bhiwandi</consignor-city>
<consignee-city>Mumbai</consignee-city>
<type>TripOrder</type>
<charges>
<toll-charge>100.0</toll-charge>
<notes>
<loading-charge>90010, 90011</loading-charge>
</notes>
</charges>
<lrs type="array">
<lr>
<number>90010</number>
<consignor-city>Bhiwandi</consignor-city>
<consignee-city>Mumbai</consignee-city>
<type>Lr</type>
</lr>
<lr>
<number>90011</number>
<consignor-city>Bhiwandi</consignor-city>
<consignee-city>Mumbai</consignee-city>
<type>Lr</type>
</lr>
</lrs>
</transport-order>
<transport-order type="Lr">
<number>2664</number>
<consignor-city>Mumbai</consignor-city>
<consignee-city>Bangalore</consignee-city>
<type>Lr</type>
</transport-order>
</transport-orders>
</invoice>
我想逐行打印所有 LR 详细信息(编号、发货人城市、收货人城市)。
以下是我的代码,我尝试打印 lrs
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="invoice">
<xsl:apply-templates mode="second-page-details" select="transport-orders/transport-order"/>
</xsl:template>
<xsl:template match="*" mode="second-page-details" >
<xsl:choose>
<xsl:when test="type = 'TripOrder'">
<xsl:template match="/">
<td style="width:4.5%;border-right:solid 1px;"> <xsl:value-of select="number"/></td>
</xsl:template>
</xsl:when>
<xsl:otherwise>
<td style="width:4.5%;border-right:solid 1px;"> <xsl:value-of select="number"/></td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
我想将所有 Lr 详细信息输出为
2663
90010
90011
2664
当传输顺序类型=“TripOrder”时,我如何获取子节点(lrs)。 我希望有一些方法可以在其 TripOrder 时遍历到 Lr,以便我可以打印 LR
【问题讨论】:
-
到目前为止你尝试过什么?
-
我假设您有一个运输订单类型=“TripOrder”的匹配模板?请张贴一些xsl
-
我正在使用单个模板@ChristianMosz。
-
我尝试了一些来自互联网的东西并没有完全锻炼@Rupesh_Kr。请帮忙
-
在你预期的输出中,为什么显示2663,它的父transport-order类型不是TripOrder。