对于每个“ paymentSummaries”部分,将创建一个新表,我已经能够使它起作用。什么是行不通的paymentSummary / splitCode /(number)(type)(policyDetails)(amountPaid)到显示(返回)不只是每个表中的第一个实例。
这是我的XML:
<paymentSummaries>
<billingAccountNumber>billingAccountNumber1</billingAccountNumber>
<paymentSummary>
<splitCode>
<number>paymentSummary1</number>
<type>type1</type>
<policyDetails>policyDetails1</policyDetails>
<amountPaid>amountPaid1</amountPaid>
</splitCode>
</paymentSummary>
<paymentSummary>
<splitCode>
<number>paymentSummary2</number>
<type>type2</type>
<policyDetails>policyDetails2</policyDetails>
<amountPaid>amountPaid2</amountPaid>
</splitCode>
</paymentSummary>
<serviceFee>serviceFee1</serviceFee>
<totalAmountPaid>totalAmountPaid1</totalAmountPaid>
</paymentSummaries>
这是我到目前为止尝试过的。第一个示例仅返回第一个例子。第二个示例不返回任何内容/空白。
第一个例子:
我有一个
<xsl:for-each select="SFF/*[local-name()='paymentReceipt']/*[local-name()='paymentSummaries']">
环绕整个桌子(这样可以重复该桌子每个通过。对于单个子元素和兄弟元素,我没有指定任何
<for-each>
或<if>
测试是因为我认为它只会重复实例。第二示例:
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<xsl:if test="SFF/*[local-name()='paymentReceipt']/*[local-name()='paymentSummaries']/*[local-name()='paymentSummary']/*[local-name()='splitCode'][1]/*[local-name()='number'] != ''">
<td align="left" valign="top" style="padding: 8px 5px 0px 10px;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="170" height="25" align="left" valign="top" class="fl wrap width150">
<div class="FS13 LH18" style="font-family: Arial Narrow, Arial, Helvetica, sans-serif;font-size:14px; line-height:20px; color:#313131; font-weight:normal;">
<xsl:value-of select="SFF/*[local-name()='paymentReceipt']/*[local-name()='paymentSummaries']/*[local-name()='paymentSummary']/*[local-name()='splitCode'][1]/*[local-name()='number']"></xsl:value-of>
</div>
</td>
<td width="270" height="25" align="left" valign="top" class="fl wrap width150">
<div class="FS13 LH18" style="font-family: Arial Narrow, Arial, Helvetica, sans-serif;font-size:14px; line-height:20px; color:#313131; font-weight:normal;">
<xsl:value-of select="SFF/*[local-name()='paymentReceipt']/*[local-name()='paymentSummaries']/*[local-name()='paymentSummary']/*[local-name()='splitCode'][1]/*[local-name()='type']"></xsl:value-of>
</div>
</td>
</tr>
</table>
</td>
<td width="95" align="right" valign="top" class="width150" style="padding: 8px 5px 0px 10px;">
<div class="FS13 LH18" style="font-size:14px; line-height:20px; color:#313131; font-weight:normal;font-family: Arial Narrow, Arial, Helvetica, sans-serif;">
<xsl:value-of select="*[local-name()='paymentReceipt']/*[local-name()='paymentSummaries']/*[local-name()='paymentSummary']/*[local-name()='splitCode'][1]/*[local-name()='amountPaid']"</xsl:value-of>
</div>
</td>
</xsl:if>
</tr>
<xsl:for-each select="*[local-name()='paymentReceipt']/*[local-name()='paymentSummaries']/*[local-name()='paymentSummary']/*[local-name()='splitCode'][position() >1]">
<tr>
<td align="left" valign="top" style="padding: 8px 5px 0px 10px;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="170" height="25" align="left" valign="top" class="fl wrap width150">
<div class="FS13 LH18" style="font-family: Arial Narrow, Arial, Helvetica, sans-serif;font-size:14px; line-height:20px; color:#313131; font-weight:normal;">
<xsl:value-of select="*[local-name()='number']"></xsl:value-of>
</div>
</td>
<td width="270" height="25" align="left" valign="top" class="fl wrap width150">
<div class="FS13 LH18" style="font-family: Arial Narrow, Arial, Helvetica, sans-serif;font-size:14px; line-height:20px; color:#313131; font-weight:normal;">
<xsl:value-of select="*[local-name()='type']"></xsl:value-of>
</div>
</td>
</tr>
</table>
</td>
<td width="95" align="right" valign="top" class="width150" style="padding: 8px 5px 0px 10px;">
<div class="FS13 LH18" style="font-size:14px; line-height:20px; color:#313131; font-weight:normal;font-family: Arial Narrow, Arial, Helvetica, sans-serif;">
<xsl:value-of select="*[local-name()='amountPaid']"></xsl:value-of>
</div>
</td>
</tr>
</xsl:for-each>
<tr bgcolor="#ffffff">
<xsl:if test="SFF/*[local-name()='paymentReceipt']/*[local-name()='paymentSummaries']/*[local-name()='paymentSummary']/*[local-name()='splitCode'][1]/*[local-name()='policyDetails'] != ''">
<td align="left" valign="top" style="padding: 0px 5px 8px 10px;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="175" align="left" valign="top" class="fl wrap width150">
<div class="FS13 LH18" style="font-family: Arial Narrow, Arial, Helvetica, sans-serif;font-size:14px; line-height:20px; color:#313131; font-weight:normal;">
</div>
</td>
<td width="270" align="left" valign="top" class="fl wrap width150">
<div class="FS13 LH18" style="font-family: Arial Narrow, Arial, Helvetica, sans-serif;font-size:14px; line-height:20px; color:#313131; font-weight:normal;">
<xsl:value-of select="*[local-name()='splitCode'][1]/*[local-name()='policyDetails']" />
</div>
</td>
</tr>
</table>
</td>
</xsl:if>
</tr>
<table>
[这就是我要得到的表1:paymentSummary1 type1 amountPaid1policyDetails1(此表缺少paymentSummary2,type2等)
表2:paymentSummary3 type3 amountPaid3(此表是缺少paymentSummary4,type4等。policyDetails3
关于如何使它正常工作的任何想法?
[我想我可以看到您要执行的操作:将所有付款摘要放在一个表中,然后是单个policyDetail
您首先说“对于每个'paymentSummaries'部分,将创建一个新表...”
因此,您首先要这样做:
<xsl:template select='/'>
<xsl:for-each select='//paymentSummaries'>
<table>
<xsl:apply-templates select='paymentSummary'/>
<xsl:call-template name='policy'/>
</table>
</xsl:for-each>
</xsl:template>
接下来,您需要决定要对每个paymentSummary块执行的操作。在这里,我只是向表中添加新行
<xsl:template match='paymentSummary'>
<tr>
<td>
<xsl:value-of select='splitCode/number'/>
</td>
<td>
<xsl:value-of select='splitCode/type'/>
</td>
<td>
<xsl:value-of select='splitCode/amountPaid'/>
</td>
</tr>
</xsl:template>
最后,我添加了策略部分:请注意调用模板而不是套用模板,因为我只想执行一次。
<xsl:template name='policy'>
<tr>
<td>
<xsl:value-of select='paymentSummary[1]/splitCode/policyDetails'/>
</td>
</tr>
</xsl:template>
一旦有了所需的总体布局,继续并按您自己的样式进行设置