首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模板名称和调用模板

问模板名称和调用模板
EN

Stack Overflow用户
提问于 2022-10-11 10:45:25
回答 1查看 29关注 0票数 1

我有用于更改状态事务的xslt。我可以更改模板谁在范围内的模板名bodys。但是,计划是当头数据出现故障时,节点TxRsnSts中模板体的状态也需要更改。但是我无法从标题中得到值。如何从头获取值并在变量名称TxRsnStsB上提交。

这是我制作的XSLT脚本

代码语言:javascript
复制
<xsl:stylesheet version="1.0" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns1="urn:iso:std:iso:20022:tech:xsd:head.001.001.01" xmlns:ns2="urn:iso:std:iso:20022:tech:xsd:pacs.002.001.10" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output indent="no" method="xml" omit-xml-declaration="yes"/>
        <xsl:template match="/">
            <ns:BusMsg xmlns:ns="urn:iso" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso ../../../xsd/phase1/MainCIHub.xsd">
                <ns1:AppHdr>
                    <xsl:call-template name="headers">
                        <xsl:with-param name="CpyDplct" select="//BusMsg/AppHdr/CpyDplct"/>
                        <xsl:with-param name="PssblDplct" select="//BusMsg/AppHdr/PssblDplct"/>
                        <xsl:with-param name="Sgntr" select="//BusMsg/AppHdr/Sgntr"/>
                    </xsl:call-template>
                </ns1:AppHdr>
                <ns:Document>
                    <ns:FIToFIPmtStsRpt>
                        <xsl:call-template name="bodys">
                            <xsl:with-param name="CtgyPurpB" select="//BusMsg/Document/FItoFICstmrCdtTrf/CdtTrfTxInf/PmtTpInf/CtgyPurp/Prtry"/>
                            <xsl:with-param name="IntrBkSttlmAmtB" select="//BusMsg/Document/FItoFICstmrCdtTrf/CdtTrfTxInf/IntrBkSttlmAmt/Value"/>
                            <xsl:with-param name="CcyB" select="//BusMsg/Document/FItoFICstmrCdtTrf/CdtTrfTxInf/IntrBkSttlmAmt/Ccy"/>
                        </xsl:call-template>
                    </ns:FIToFIPmtStsRpt>
                </ns:Document>
            </ns:BusMsg>
        </xsl:template>
        
        <xsl:template name="headers">
            <xsl:param name="CpyDplct"/>
            <xsl:param name="PssblDplct"/>
            <xsl:param name="Sgntr"/>
            <xsl:variable name="flagCpyDplcts">
                <xsl:choose>
                    <xsl:when test="$CpyDplct = ''"/>
                    <xsl:when test="string-length($CpyDplct) &lt;= 35 and ($CpyDplct = 'CODU' or $CpyDplct = 'COPY' or $CpyDplct = 'DUPL')">
                        <xsl:value-of select="$CpyDplct"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:copy>
                            <xsl:copy-of select="$CpyDplct"/>
                        </xsl:copy>
                        <xsl:value-of select="'U0002'"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            
            <xsl:variable name="flagPssblDplcts">
                <xsl:choose>
                    <xsl:when test="$PssblDplct = ''"/>
                    <xsl:when test="string-length($PssblDplct) &lt;= 35 and ($PssblDplct = 'true' or $PssblDplct = 'false')">
                        <xsl:value-of select="$PssblDplct"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:copy>
                            <xsl:copy-of select="$PssblDplct"/>
                        </xsl:copy>
                        <xsl:value-of select="'U0002'"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <xsl:variable name="flagSgntrs">
                <xsl:choose>
                    <xsl:when test="$Sgntr = ''"/>
                    <xsl:when test="string-length($Sgntr) &lt;= 35">
                        <xsl:value-of select="$Sgntr"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:copy>
                            <xsl:copy-of select="$PssblDplct"/>
                        </xsl:copy>
                        <xsl:value-of select="'U0012'"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <ns1:CpyDplct>
                <xsl:value-of select="$flagCpyDplcts"/>
            </ns1:CpyDplct>
            <ns1:PssblDplct>
                <xsl:value-of select="$flagPssblDplcts"/>
            </ns1:PssblDplct>
            <ns1:Sgntr>
                <xsl:value-of select="$flagSgntrs"/>
            </ns1:Sgntr>
        </xsl:template>
        <xsl:template name="bodys">
            <xsl:param name="CtgyPurpB"/>
            <xsl:param name="IntrBkSttlmAmtB"/>
            <xsl:param name="CcyB"/>
            <xsl:variable name="flagCtgyPurpBs">
                <xsl:variable name="payT" select="substring($CtgyPurpB,1,3)"/>
                <xsl:variable name="catP" select="substring($CtgyPurpB,4,2)"/>
                <xsl:choose>
                    <xsl:when test="not(contains($payT,'010') or contains($payT,'011') or contains($payT,'019') or contains($payT,'110') or contains($payT,'510') or contains($payT,'610') or contains($payT,'710') or contains($payT,'720') or contains($payT,'000'))">
                        <xsl:value-of select="'U0002'"/>
                    </xsl:when>
                    <xsl:when test="not(contains($catP,'01') or contains($catP,'02') or contains($catP,'03') or contains($catP,'99'))">
                        <xsl:value-of select="'U0002'"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$CtgyPurpB"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <xsl:variable name="flagIntrBkSttlmAmtBs">
                <xsl:variable name="amount" select="substring-before($IntrBkSttlmAmtB,'.')"/>
                <xsl:variable name="decimal" select="substring-after($IntrBkSttlmAmtB,'.')"/>
                <xsl:choose>
                    <xsl:when test="not(fn:matches($IntrBkSttlmAmtB, '^[0-9.]*$'))">
                        <xsl:value-of select="'U0038'"/>
                    </xsl:when>
                    <xsl:when test="not(string-length($amount) &lt;= 16)">
                        <xsl:value-of select="'U0038'"/>
                    </xsl:when>
                    <xsl:when test="not(string-length($decimal) &lt;= 2)">
                        <xsl:value-of select="'U0038'"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$IntrBkSttlmAmtB"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <xsl:variable name="flagCcyBs">
                <xsl:choose>
                    <xsl:when test="not(fn:matches($CcyB, '^[a-zA-Z0-9]*$') and string-length($CcyB) &lt;= 3)">
                        <xsl:value-of select="'U0038'"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$CcyB"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <ns1:CtgyPurp>
                <xsl:value-of select="$flagCtgyPurpBs"/>
            </ns1:CtgyPurp>
            <ns1:IntrBkSttlmAmt>
                <xsl:value-of select="$flagIntrBkSttlmAmtBs"/>
            </ns1:IntrBkSttlmAmt>
            <ns1:Ccy>
                <xsl:value-of select="$flagCcyBs"/>
            </ns1:Ccy>
            <xsl:variable name="TxRsnStsB">
                <xsl:choose>
                    <xsl:when
                        test="contains($flagSgntrs, 'U0012') or contains($flagSgntrs, 'U0002') or contains($flagSgntrs, 'U0038') or contains($flagPssblDplcts, 'U0012') or contains($flagPssblDplcts, 'U0002') or contains($flagPssblDplcts, 'U0038') or contains($flagCpyDplcts, 'U0012') or contains($flagCpyDplcts, 'U0002') or contains($flagCpyDplcts, 'U0038') or contains($flagCtgyPurpBs, 'U0012') or contains($flagCtgyPurpBs, 'U0002') or contains($flagCtgyPurpBs, 'U0038')      or contains($flagIntrBkSttlmAmtBs, 'U0012') or contains($flagIntrBkSttlmAmtBs, 'U0002') or contains($flagIntrBkSttlmAmtBs, 'U0038') or contains($flagCcyBs, 'U0012') or contains($flagCcyBs, 'U0002') or contains($flagCcyBs, 'U0038')">
                        <xsl:value-of select="'Decline'" />
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="'Approve'" />
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <ns1:TxRsnSts><xsl:value-of select="$TxRsnStsB"/></ns1:TxRsnSts>
        </xsl:template>
    </xsl:stylesheet>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-11 14:25:00

你的问题很难理解。如果要重用在正文中标头中声明的变量标记,则有两个选项:在变量中保存标头的结果,并将其用作调用body的参数。另一个选项是将这些变量声明为全局变量,如下所示:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:fn="http://www.w3.org/2005/xpath-functions" 
  xmlns:ns1="urn:iso:std:iso:20022:tech:xsd:head.001.001.01" 
  xmlns:ns2="urn:iso:std:iso:20022:tech:xsd:pacs.002.001.10" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output indent="no" method="xml" omit-xml-declaration="yes"/>

  <xsl:variable name="CpyDplct" select="//BusMsg/AppHdr/CpyDplct"/>
  <xsl:variable name="PssblDplct" select="//BusMsg/AppHdr/PssblDplct"/>
  <xsl:variable name="Sgntr" select="//BusMsg/AppHdr/Sgntr"/>

  <xsl:variable name="flagCpyDplcts">
    <xsl:choose>
      <xsl:when test="$CpyDplct = ''"/>
      <xsl:when test="string-length($CpyDplct) &lt;= 35 and ($CpyDplct = 'CODU' or $CpyDplct = 'COPY' or $CpyDplct = 'DUPL')">
        <xsl:value-of select="$CpyDplct"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy>
          <xsl:copy-of select="$CpyDplct"/>
        </xsl:copy>
        <xsl:value-of select="'U0002'"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  
  <xsl:variable name="flagPssblDplcts">
    <xsl:choose>
      <xsl:when test="$PssblDplct = ''"/>
      <xsl:when test="string-length($PssblDplct) &lt;= 35 and ($PssblDplct = 'true' or $PssblDplct = 'false')">
        <xsl:value-of select="$PssblDplct"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy>
          <xsl:copy-of select="$PssblDplct"/>
        </xsl:copy>
        <xsl:value-of select="'U0002'"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  
  <xsl:variable name="flagSgntrs">
    <xsl:choose>
      <xsl:when test="$Sgntr = ''"/>
      <xsl:when test="string-length($Sgntr) &lt;= 35">
        <xsl:value-of select="$Sgntr"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy>
          <xsl:copy-of select="$PssblDplct"/>
        </xsl:copy>
        <xsl:value-of select="'U0012'"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  
  <xsl:template match="/">
    <ns:BusMsg xmlns:ns="urn:iso" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso ../../../xsd/phase1/MainCIHub.xsd">
      <ns1:AppHdr>
        <xsl:call-template name="headers"/>
      </ns1:AppHdr>
      <ns:Document>
        <ns:FIToFIPmtStsRpt>
          <xsl:call-template name="bodys">
            <xsl:with-param name="CtgyPurpB" select="//BusMsg/Document/FItoFICstmrCdtTrf/CdtTrfTxInf/PmtTpInf/CtgyPurp/Prtry"/>
            <xsl:with-param name="IntrBkSttlmAmtB" select="//BusMsg/Document/FItoFICstmrCdtTrf/CdtTrfTxInf/IntrBkSttlmAmt/Value"/>
            <xsl:with-param name="CcyB" select="//BusMsg/Document/FItoFICstmrCdtTrf/CdtTrfTxInf/IntrBkSttlmAmt/Ccy"/>
          </xsl:call-template>
        </ns:FIToFIPmtStsRpt>
      </ns:Document>
    </ns:BusMsg>
  </xsl:template>
  
  <xsl:template name="headers">
    <ns1:CpyDplct>
      <xsl:value-of select="$flagCpyDplcts"/>
    </ns1:CpyDplct>
    <ns1:PssblDplct>
      <xsl:value-of select="$flagPssblDplcts"/>
    </ns1:PssblDplct>
    <ns1:Sgntr>
      <xsl:value-of select="$flagSgntrs"/>
    </ns1:Sgntr>
  </xsl:template>
  
  <xsl:template name="bodys">
    <xsl:param name="CtgyPurpB"/>
    <xsl:param name="IntrBkSttlmAmtB"/>
    <xsl:param name="CcyB"/>
    <xsl:param name="header"/>
    <xsl:variable name="flagCtgyPurpBs">
      <xsl:variable name="payT" select="substring($CtgyPurpB,1,3)"/>
      <xsl:variable name="catP" select="substring($CtgyPurpB,4,2)"/>
      <xsl:choose>
        <xsl:when test="not(contains($payT,'010') or contains($payT,'011') or contains($payT,'019') or contains($payT,'110') or contains($payT,'510') or contains($payT,'610') or contains($payT,'710') or contains($payT,'720') or contains($payT,'000'))">
          <xsl:value-of select="'U0002'"/>
        </xsl:when>
        <xsl:when test="not(contains($catP,'01') or contains($catP,'02') or contains($catP,'03') or contains($catP,'99'))">
          <xsl:value-of select="'U0002'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$CtgyPurpB"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="flagIntrBkSttlmAmtBs">
      <xsl:variable name="amount" select="substring-before($IntrBkSttlmAmtB,'.')"/>
      <xsl:variable name="decimal" select="substring-after($IntrBkSttlmAmtB,'.')"/>
      <xsl:choose>
        <xsl:when test="not(fn:matches($IntrBkSttlmAmtB, '^[0-9.]*$'))">
          <xsl:value-of select="'U0038'"/>
        </xsl:when>
        <xsl:when test="not(string-length($amount) &lt;= 16)">
          <xsl:value-of select="'U0038'"/>
        </xsl:when>
        <xsl:when test="not(string-length($decimal) &lt;= 2)">
          <xsl:value-of select="'U0038'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$IntrBkSttlmAmtB"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="flagCcyBs">
      <xsl:choose>
        <xsl:when test="not(fn:matches($CcyB, '^[a-zA-Z0-9]*$') and string-length($CcyB) &lt;= 3)">
          <xsl:value-of select="'U0038'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$CcyB"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <ns1:CtgyPurp>
      <xsl:value-of select="$flagCtgyPurpBs"/>
    </ns1:CtgyPurp>
    <ns1:IntrBkSttlmAmt>
      <xsl:value-of select="$flagIntrBkSttlmAmtBs"/>
    </ns1:IntrBkSttlmAmt>
    <ns1:Ccy>
      <xsl:value-of select="$flagCcyBs"/>
    </ns1:Ccy>
    <xsl:variable name="TxRsnStsB">
      <xsl:choose>
        <xsl:when test="contains($flagSgntrs, 'U0012') or contains($flagSgntrs, 'U0002') or contains($flagSgntrs, 'U0038') or contains($flagPssblDplcts, 'U0012') or contains($flagPssblDplcts, 'U0002') or contains($flagPssblDplcts, 'U0038') or contains($flagCpyDplcts, 'U0012') or contains($flagCpyDplcts, 'U0002') or contains($flagCpyDplcts, 'U0038') or contains($flagCtgyPurpBs, 'U0012') or contains($flagCtgyPurpBs, 'U0002') or contains($flagCtgyPurpBs, 'U0038')      or contains($flagIntrBkSttlmAmtBs, 'U0012') or contains($flagIntrBkSttlmAmtBs, 'U0002') or contains($flagIntrBkSttlmAmtBs, 'U0038') or contains($flagCcyBs, 'U0012') or contains($flagCcyBs, 'U0002') or contains($flagCcyBs, 'U0038')">
          <xsl:value-of select="'Decline'" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="'Approve'" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <ns1:TxRsnSts><xsl:value-of select="$TxRsnStsB"/></ns1:TxRsnSts>
  </xsl:template>
</xsl:stylesheet>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74026831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档