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