繁体   English   中英

XSLT:使用参数调用模板并连接多个值

[英]XSLT: Call Template with Parameter and Concatenate several values

我的xml代码的一部分如下:

<PaymentInstruction>
                <ID> 1</ID>
                <Code listID="1C">POST</Code>
                <CodeDescription languageCode="RU">PostType</CodeDescription>
                <Note languageCode="RU">01</Note>
            </PaymentInstruction>
            <PaymentInstruction>
                <ID> 2</ID>
                <Code listID="1C">PAYTYPE</Code>
                <CodeDescription languageCode="RU">PayType</CodeDescription>
                <Note languageCode="RU">Electronic</Note>
            </PaymentInstruction>
            <PaymentInstruction>
                <ID> 3</ID>
                <Code listID="1C">INN_PAY</Code>
                <CodeDescription languageCode="RU">INNPayer</CodeDescription>
                <Note languageCode="RU">987654321</Note>
            </PaymentInstruction>

我在XSLT的某个地方写了这样的代码:

<xsl:template match="PaymentInstruction">
        <xsl:param name="value" select="0"/>             
        <xsl:choose>
            <xsl:when test="$value = 'POST'"><xsl:if test="Code = 'POST'">
<xsl:value-of select="Note"></xsl:value-of></xsl:if></xsl:when>
            <xsl:when test="$value = 'PAYTYPE'"><xsl:if test="Code = 'PAYTYPE'">
<xsl:value-of select="Note"></xsl:value-of></xsl:if></xsl:when>
            <xsl:when test="$value = 'INN_PAY'"><xsl:if test="Code = 'INN_PAY'">
<xsl:value-of select="Note"></xsl:value-of></xsl:if></xsl:when> 
        </xsl:choose>        
</xsl:template>        

+

Payer=<xsl:value-of select="concat('INN ',PaymentInstruction/Code='INN_PAY', '\',PaymentInstruction/Code='PAYTYPE', ' ', $Payer)"/>    

最后,我得到以下输出:

Payer=INN true\false Payer_Full_Name    

但我想输出以下内容:

Payer=INN 987654321\Electronic Payer_Full_Name    

我怎样才能做到这一点? 谢谢!

尝试这个,

<xsl:value-of select="concat('INN ', if(PaymentInstruction/Code='INN_PAY') then PaymentInstruction[Code='INN_PAY']/Note else 'SOME OTHER', )"/>

公平地说,您似乎必须将“ Payer”组成代码从您在此处发布的集合中移到上一层。

<xsl:template match="/">
        <xsl:variable name="Payer">Payer_Full_Name</xsl:variable>
        <xsl:variable name="Innpay"><xsl:value-of select="//PaymentInstruction/Code[.='INN_PAY']/../Note"></xsl:value-of></xsl:variable>
        <xsl:variable name="Paytype"><xsl:value-of select="//PaymentInstruction/Code[.='PAYTYPE']/../Note"></xsl:value-of></xsl:variable>
    <xsl:element name="Output">
        <xsl:attribute name="result">Payer=<xsl:value-of select="concat('INN ', $Innpay, '\', $Paytype, ' ', $Payer)"/></xsl:attribute>
    </xsl:element>
</xsl:template>

希望这是您要寻找的东西:

<Output result="Payer=INN 987654321\Electronic Payer_Full_Name" ... />

PS可以随意将“ // PaymentInstruction”调整为标签的真实级别-唯一的规则应该是在收集级别,而不是在单独的<PaymentInstruction>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM