简体   繁体   中英

XSLT: Call Template with Parameter and Concatenate several values

Part of my xml code is as follows:

<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>

Somewhere in the XSLT I wrote code something like this:

<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)"/>    

And in the end I get the following output:

Payer=INN true\false Payer_Full_Name    

But I want to output the following:

Payer=INN 987654321\Electronic Payer_Full_Name    

How can I do this? Thanks!

尝试这个,

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

To be fair, it seems you have to move your "Payer" composing code one level above from the collection you posted here.

<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>

Hope this is sort of what you're looking for:

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

PS Feel free to adjust "//PaymentInstruction" to the real level of your tags - the only rule you should be at the collection level, not at individual <PaymentInstruction>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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