连接字符串,包括重复标记



输入XML:

<?xml version='1.0' encoding='UTF-8'?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn-sample">
  <CustomerRecord>
    <Statement>
      <StmtId>123</StmtId>
      <StmtDate>2013-08-16</StmtDate>
      <AcctNumber>123456789</AcctNumber>
      <Balance>
        <Type>OP</Type>
        <Amount>1.00</Amount>
        <CreditOrDebit>DR</CreditOrDebit>
        <Date>2013-08-15</Date>
      </Balance>
      <Balance>
        <Type>CL</Type>
        <Amount>2.00</Amount>
        <CreditOrDebit>CR</CreditOrDebit>
        <Date>2013-08-16</Date>
      </Balance>
      <Balance>
        <Type>FW</Type>
        <Amount>3.00</Amount>
        <CreditOrDebit>CR</CreditOrDebit>
        <Date>2013-08-17</Date>
      </Balance>
      <Entry>
        <Amount>7778.70</Amount>
        <CreditOrDebit>DR</CreditOrDebit>
        <EntryDtls>
          <TransactionDetails>
            <Parties>
              <Customer>
                <Name>Customer 1 Name</Name>
                <Address>Address Line 1</Address>
              </Customer>
              <CustomerAcct>
                <AcctName>Account Name 1</AcctName>
                <AcctNumber>12345677</AcctNumber>
              </CustomerAcct>
            </Parties>
            <AddlInfo>
              <Info1>Info 1</Info1>
              <Info1>Info 2</Info1>
              <Info1>Info 3</Info1>
            </AddlInfo>
          </TransactionDetails>
        </EntryDtls>
      </Entry>
    </Statement>
  </CustomerRecord>
</Document>

对于Description标签CStatement/CStatementLine/Description应该有这样的输出:

<?xml version="1.0" encoding="utf-8"?>
<Root> <!--should have no attribute-->
  <CStatement>
    <CStatementId>123</CStatementId>
    <CStatementDate>2013-08-16</CStatementDate>
    <AccountNumber>123456789</AccountNumber>
    <OpeningBalance>-1.00</OpeningBalance>
    <ClosingBalance>2.00</ClosingBalance>
    <CStatementLine>
      <DebitOrCredit>DR</DebitOrCredit>
      <Amount>-7778.70</Amount>
      <CustomerName>Customer 1 Name</CustomerName>
      <CustomerBankAccount>12345677</CustomerBankAccount>
      <Description>CUST+Customer 1 Name+Address Line 2+ACCT+Account Name 1+12345677+ADDL+Info 1+Info 2+Info 3</Description>
    </CStatementLine>
  </CStatement>
</Root>

我不确定如何使用变量或任何函数来存储具有此要求的Description标签的值:

  • 。连接字符串'CUST' +客户/名称+客户/地址
  • b。连接字符串'ACCT' + CustomerAcct/AcctName + CustomerAcct/AcctNumber
  • c。连接字符串'ADDL' +值有在AddlInfo/Info1 (1..n)
  • 连接a+b+c ....等
我希望有人能帮我解决这个问题。谢谢大家

顺便说一句,我需要XSLT 1.0

看看是否有帮助:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:urn="urn-sample"
exclude-result-prefixes="urn">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:template match="/urn:Document">
    <Root>
        <xsl:apply-templates select="urn:CustomerRecord/urn:Statement" />
    </Root>
</xsl:template>
<xsl:template match="urn:Statement">
    <CStatement>
        <CStatementId>
            <xsl:value-of select="urn:StmtId"/>
        </CStatementId>
        <!-- more -->
        <xsl:apply-templates select="urn:Entry" />
    </CStatement>
</xsl:template>
<xsl:template match="urn:Entry">
    <StatementLine>
        <Description>
            <xsl:text>CUST+</xsl:text>
            <xsl:value-of select="urn:EntryDtls/urn:TransactionDetails/urn:Parties/urn:Customer/urn:Name" />
            <xsl:text>+</xsl:text>
            <xsl:value-of select="urn:EntryDtls/urn:TransactionDetails/urn:Parties/urn:Customer/urn:Address" />
            <!-- more of the same -->
            <xsl:text>+ADDL+</xsl:text>
            <xsl:for-each select="urn:EntryDtls/urn:TransactionDetails/urn:AddlInfo/urn:Info1">
                <xsl:value-of select="." />
                <xsl:if test="position()!=last()">
                    <xsl:text>+</xsl:text>
                </xsl:if>
            </xsl:for-each>
        </Description>
    </StatementLine>
</xsl:template>
</xsl:stylesheet>

你也可以使用concat()函数,例如:

<xsl:value-of select="concat('CUST+', urn:EntryDtls/urn:TransactionDetails/urn:Parties/urn:Customer/urn:Name)" />

相关内容

  • 没有找到相关文章

最新更新