xml - XSLT:不允许将多个项目的序列作为 fn:substring() 的第一个参数
问题描述
从下面的 XML 中,我尝试替换/ABC/
为/DEF/
,但我遇到了错误。
错误:不允许将多个项目的序列作为 fn:substring() 的第一个参数
XML:
<?xml version="1.0" encoding="utf-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">
<CstmrCdtTrfInitn>
<GrpHdr>
<MsgId>fhjfdgh</MsgId>
<NbOfTxs>2</NbOfTxs>
</GrpHdr>
<PmtInf>
<PmtInfId>21351</PmtInfId>
<NbOfTxs>2</NbOfTxs>
<CdtTrfTxInf>
<PmtId>
<InstrId>124512</InstrId>
<EndToEndId>24523q</EndToEndId>
</PmtId>
<InstrForDbtrAgt>/ABC/245334524362356235</InstrForDbtrAgt>
</CdtTrfTxInf>
<CdtTrfTxInf>
<PmtId>
<InstrId>45234</InstrId>
<EndToEndId>42353</EndToEndId>
</PmtId>
<InstrForDbtrAgt>/ABC/111334524362356235</InstrForDbtrAgt>
</CdtTrfTxInf>
</PmtInf>
</CstmrCdtTrfInitn>
</Document>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:cc1="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="cc1" version="2.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/cc1:Document/cc1:CstmrCdtTrfInitn/cc1:PmtInf/cc1:CdtTrfTxInf/cc1:InstrForDbtrAgt">
<xsl:element namespace="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" name="InstrForDbtrAgt">
<xsl:variable name="InstrForDbtrAgtInv" select="substring(../../cc1:CdtTrfTxInf/cc1:InstrForDbtrAgt, 7, 200)"/>
<xsl:value-of select="concat('/DEF/', $InstrForDbtrAgtInv)"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
解决方案
我正在尝试用 /DEF/ 替换 /ABC/
我认为您将非常简单的事情过度复杂化了:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="InstrForDbtrAgt">
<xsl:copy>
<xsl:value-of select="replace(., '/ABC/', '/DEF/')"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
推荐阅读
- api - Flask API 用于发布数据和图像
- reactjs - 如何在 redux 状态下添加/更改属性?
- angular - 如何将 ngx-monaco-editor 包装在 ControlValueAccessor 组件中
- postgresql - Knex(使用 Expressjs)和 postgresSQL:字符串在 SQL 中由 knex 自动双引号
- maven - 在 Mac OSX Catalina (10.15.4) 上找不到 maven
- reactjs - 如何使用 react-redux 在功能组件中调用动作创建者?
- javascript - 我想了解为什么它会这样工作
- php - 更改 PHP 创建的图像的 html 标题
- r - 在 R 中使用“ddply”和“glm”进行 k 值估计(双曲线延迟折扣)时出错
- python - 如何导入修改后的库而不是以前安装的库?