请允许我在这里提出一个我目前遇到的问题:
有两个文件:
- 包含表示操作(历史)标记的XML文件
- 特定操作的标签文件(两个文件的共同点是操作参考)
我将标签文件加载到xslt中,并遍历数组以构建输出。我进行了一个测试,以了解是否在标签文件中找到了当前节点的引用,因此我恢复了位于文件中的标签以供显示。下面是我的代码(循环部分):
<xsl:variable name="file-extrait-labels" select="'../../../../../../../../Ressources-bank/xml-xsl/EXTRAIT-10765280004-01102021-31122021.xml'" />
<xsl:variable name="table-extrait-labels" select="document($file-extrait-labels)/transactions-reals-labels" />
<table-movement struct="table">
<xsl:for-each select="/ACCOUNT_EXTRACTION/MOVEMENT">
<ligne struct="row">
<mvt.date><xsl:value-of select="normalize-space (@MOVEMENT_DATE)" /></mvt.date>
<mvt.ref><xsl:value-of select="normalize-space (@MOVEMENT_ACCOUNTING_RECORD)" /></mvt.ref>
<xsl:choose>
<xsl:when test="$table-extrait-labels/transaction[reference = @MOVEMENT_ACCOUNTING_RECORD]">
<mvt.lib>
<xsl:value-of select="normalize-space ($table-extrait-labels/transaction[reference = @MOVEMENT_ACCOUNTING_RECORD]/label)"/>
</mvt.lib>
</xsl:when>
<xsl:otherwise>
<mvt.lib><xsl:value-of select="normalize-space (@MOVEMENT_DESCRIPTION)" /></mvt.lib>
<xsl:choose>
<xsl:when test="LABELS">
<mvt.label><xsl:value-of select="concat(' - ', normalize-space (LABELS[1]/@LABEL))" /></mvt.label>
</xsl:when>
<xsl:otherwise>
<mvt.label><xsl:value-of select="''" /></mvt.label>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</ligne>
</xsl:for-each>
</table-movement>
问题是,尽管标签文件中确实存在引用,但它不起作用。谢谢你的帮助。
部分事务xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<ACCOUNT_EXTRACTION>
<MOVEMENT MOVEMENT_DESCRIPTION="TENUE COMPTE / FOND GARANTIE R" MOVEMENT_ACCOUNTING_RECORD="AG452032" MOVEMENT_DATE="01/11/2021" ACCOUNTING_DATE="29/10/2021" MOVEMENT_AMOUNT="6000,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="TAXE FRAIS FIXE AU 31/10/21" MOVEMENT_ACCOUNTING_RECORD="AG452032" MOVEMENT_DATE="01/11/2021" ACCOUNTING_DATE="29/10/2021" MOVEMENT_AMOUNT="1134,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="INTERETS DEBITEURS AU 31/10/21" MOVEMENT_ACCOUNTING_RECORD="AG452032" MOVEMENT_DATE="01/11/2021" ACCOUNTING_DATE="29/10/2021" MOVEMENT_AMOUNT="149,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="TAXE/INTERETS DBT AU 31/10/21" MOVEMENT_ACCOUNTING_RECORD="AG452032" MOVEMENT_DATE="01/11/2021" ACCOUNTING_DATE="29/10/2021" MOVEMENT_AMOUNT="28,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="COMM. DE DECOUVERT AU 31/10/21" MOVEMENT_ACCOUNTING_RECORD="AG452032" MOVEMENT_DATE="01/11/2021" ACCOUNTING_DATE="29/10/2021" MOVEMENT_AMOUNT="13,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="TX/COM. DECOUVERT AU 31/10/21" MOVEMENT_ACCOUNTING_RECORD="AG452032" MOVEMENT_DATE="01/11/2021" ACCOUNTING_DATE="29/10/2021" MOVEMENT_AMOUNT="2,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="VERSEMENT APPRO COMP" MOVEMENT_ACCOUNTING_RECORD="VE001302150" MOVEMENT_DATE="02/11/2021" ACCOUNTING_DATE="01/11/2021" MOVEMENT_AMOUNT="470000,0000" MOVEMENT_SIDE="C"/>
<MOVEMENT MOVEMENT_DESCRIPTION="RET DEPLAC" MOVEMENT_ACCOUNTING_RECORD="RA424988" MOVEMENT_DATE="02/11/2021" ACCOUNTING_DATE="03/11/2021" MOVEMENT_AMOUNT="200000,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="RET DAB ON US 130689454025" MOVEMENT_ACCOUNTING_RECORD="RETMO625051" MOVEMENT_DATE="02/11/2021" ACCOUNTING_DATE="03/11/2021" MOVEMENT_AMOUNT="150000,0000" MOVEMENT_SIDE="D">
<LABELS LABEL_ID="1" LABEL="10000014 - 2021/11/0222:07:34 "/>
<LABELS LABEL_ID="2" LABEL="130689454025 "/>
</MOVEMENT>
<MOVEMENT MOVEMENT_DESCRIPTION="RET DAB ON US 130689501027" MOVEMENT_ACCOUNTING_RECORD="RETMO625339" MOVEMENT_DATE="02/11/2021" ACCOUNTING_DATE="03/11/2021" MOVEMENT_AMOUNT="100000,0000" MOVEMENT_SIDE="D">
<LABELS LABEL_ID="1" LABEL="10000014 - 2021/11/0222:08:21 "/>
<LABELS LABEL_ID="2" LABEL="130689501027 "/>
</MOVEMENT>
<MOVEMENT MOVEMENT_DESCRIPTION="TENUE COMPTE / FOND GARANTIE R" MOVEMENT_ACCOUNTING_RECORD="AG526044" MOVEMENT_DATE="01/12/2021" ACCOUNTING_DATE="30/11/2021" MOVEMENT_AMOUNT="6000,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="TAXE FRAIS FIXE AU 30/11/21" MOVEMENT_ACCOUNTING_RECORD="AG526044" MOVEMENT_DATE="01/12/2021" ACCOUNTING_DATE="30/11/2021" MOVEMENT_AMOUNT="1134,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="COMMISSION DE CPTE AU 30/11/21" MOVEMENT_ACCOUNTING_RECORD="AG526044" MOVEMENT_DATE="01/12/2021" ACCOUNTING_DATE="30/11/2021" MOVEMENT_AMOUNT="158,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="TAXE COMM. DE CPTE AU 30/11/21" MOVEMENT_ACCOUNTING_RECORD="AG526044" MOVEMENT_DATE="01/12/2021" ACCOUNTING_DATE="30/11/2021" MOVEMENT_AMOUNT="30,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="COMM. DE DECOUVERT AU 30/11/21" MOVEMENT_ACCOUNTING_RECORD="AG526044" MOVEMENT_DATE="01/12/2021" ACCOUNTING_DATE="30/11/2021" MOVEMENT_AMOUNT="21,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="INTERETS DEBITEURS AU 30/11/21" MOVEMENT_ACCOUNTING_RECORD="AG526044" MOVEMENT_DATE="01/12/2021" ACCOUNTING_DATE="30/11/2021" MOVEMENT_AMOUNT="8,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="TX/COM. DECOUVERT AU 30/11/21" MOVEMENT_ACCOUNTING_RECORD="AG526044" MOVEMENT_DATE="01/12/2021" ACCOUNTING_DATE="30/11/2021" MOVEMENT_AMOUNT="4,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="TAXE/INTERETS DBT AU 30/11/21" MOVEMENT_ACCOUNTING_RECORD="AG526044" MOVEMENT_DATE="01/12/2021" ACCOUNTING_DATE="30/11/2021" MOVEMENT_AMOUNT="2,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="TENUE COMPTE / FOND GARANTIE R" MOVEMENT_ACCOUNTING_RECORD="AG634388" MOVEMENT_DATE="01/01/2022" ACCOUNTING_DATE="31/12/2021" MOVEMENT_AMOUNT="6000,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="TAXE FRAIS FIXE AU 31/12/21" MOVEMENT_ACCOUNTING_RECORD="AG634388" MOVEMENT_DATE="01/01/2022" ACCOUNTING_DATE="31/12/2021" MOVEMENT_AMOUNT="1134,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="INTERETS DEBITEURS AU 31/12/21" MOVEMENT_ACCOUNTING_RECORD="AG634388" MOVEMENT_DATE="01/01/2022" ACCOUNTING_DATE="31/12/2021" MOVEMENT_AMOUNT="80,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="TAXE/INTERETS DBT AU 31/12/21" MOVEMENT_ACCOUNTING_RECORD="AG634388" MOVEMENT_DATE="01/01/2022" ACCOUNTING_DATE="31/12/2021" MOVEMENT_AMOUNT="15,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="COMM. DE DECOUVERT AU 31/12/21" MOVEMENT_ACCOUNTING_RECORD="AG634388" MOVEMENT_DATE="01/01/2022" ACCOUNTING_DATE="31/12/2021" MOVEMENT_AMOUNT="7,0000" MOVEMENT_SIDE="D"/>
<MOVEMENT MOVEMENT_DESCRIPTION="TX/COM. DECOUVERT AU 31/12/21" MOVEMENT_ACCOUNTING_RECORD="AG634388" MOVEMENT_DATE="01/01/2022" ACCOUNTING_DATE="31/12/2021" MOVEMENT_AMOUNT="1,0000" MOVEMENT_SIDE="D"/>
</ACCOUNT_EXTRACTION>
标签xml文件的一部分:
<?xml version="1.0" encoding="UTF-8"?>
<transactions-reals-labels>
<transaction>
<reference>VE001302150</reference>
<label>Operation Match label 1</label>
</transaction>
<transaction>
<reference>RETMO625051</reference>
<label>Operation Match label 2</label>
</transaction>
<transaction>
<reference>RETMO625339</reference>
<label>Operation Match label 3</label>
</transaction>
</transactions-reals-labels>
您的表达式:
$table-extrait-labels/transaction[reference = @MOVEMENT_ACCOUNTING_RECORD]
正在寻找具有子reference
和的transaction
。aMOVEMENT_ACCOUNTING_RECORD
属性值相等。
如果您想找到transaction
的子reference
值等于上下文的MOVEMENT_ACCOUNTING_RECORD
属性的值节点(在您的示例中是当前处理的MOVEMENT
),您需要使用:
$table-extrait-labels/transaction[reference = current()/@MOVEMENT_ACCOUNTING_RECORD]
或者(最好)构造一个键并按照我在注释中指出的示例使用它。
未测试,因为没有提供可重复的示例。
还请注意,如果使用变量而不是重复XPath表达式,测试节点是否存在,然后从该节点获取数据将更有效。