且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

对于XSLT中的每个循环,仅通过第一条记录

更新时间:2022-06-26 05:41:40

我发现这些无休止的 concat()语句不可读。我建议您将它们更改为以下形式的显式指令:

I find these endless concat() statements unreadable. I would suggest you change them to explicit instructions in the form of:

<xsl:variable name="headerText">
    <xsl:value-of select="$header/ns2:MsgId"/>
    <xsl:text>,</xsl:text>
    <!-- ... -->
</xsl:variable>

某些缩进也有助于提高可读性。

Some indentation would also be useful for improving readability.

无论如何,您的错误是在 xsl之外定义了 $ CdtTrfTxInfText 变量: -每条指令。这将使用第一个 CdtTrfTxInf 节点中的值填充变量-然后您只需为每次 CdtTrfTxInf 重复这些值

Anyway, your mistake is defining the $CdtTrfTxInfText variable outside of the xsl:for-each instruction. This populates the variable with values from the first CdtTrfTxInf node - and then you simply repeat these values for each occurrence of CdtTrfTxInf.

尝试摆脱变量,直接从 xsl:for-each 中的当前节点获取值>指令:

Try getting rid of the variable and getting the values directly from the current node within the xsl:for-each instruction:

<xsl:for-each select="$pmt/ns2:CdtTrfTxInf">
    <xsl:value-of select="$headerText"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="$pmtText"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="concat(
    ns2:PmtId/ns2:EndToEndId,',',
    ns2:Amt/ns2:InstdAmt,',',
    ns2:CdtrAgt/ns2:FinInstnId/ns2:BIC,',',
    ns2:Cdtr/ns2:Nm,',',
    ns2:Cdtr/ns2:PstlAdr/ns2:AdrLine[1],',',
    ns2:Cdtr/ns2:PstlAdr/ns2:AdrLine[2],',',
    ns2:Cdtr/ns2:PstlAdr/ns2:Ctry,',',
    ns2:CdtrAcct/ns2:Id/ns2:IBAN,',',
    ns2:RmtInf/ns2:Ustrd)"/>
    <xsl:text>&#xa;</xsl:text>
</xsl:for-each>