0
<block2 type="input">
    <messageType>103</messageType>
    <receiverAddress>BKTRUS33XBRD</receiverAddress>
    <messagePriority>N</messagePriority>
    <deliveryMonitoring>3</deliveryMonitoring>
</block2>

I need output as if message type is 103. Then we pass a string like CTD.

output: CTD,I103N

2
  • Please start formatting you code using {} button. Commented Feb 15, 2011 at 11:16
  • @Flack: I really don't understand how this is different from stackoverflow.com/questions/5001480/… Commented Feb 15, 2011 at 23:29

2 Answers 2

1
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>
    <xsl:variable name="vUpper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
    <xsl:variable name="vLower" select="'abcdefghijklmnopqrstuvwxyz'"/>
    <xsl:template match="/">
        <xsl:for-each select="block2[messageType = '103']">
            <xsl:value-of select="
                concat(
                    'CTD,',
                    translate(substring(@type, 1, 1), $vLower, $vUpper),
                    messageType,
                    messagePriority
                )"/>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Output will be CTD,I103N.

In XSLT 2.0 one could use fn:upper-case and fn:lower-case.

Sign up to request clarification or add additional context in comments.

5 Comments

bro we need to check for input or output if it is input replace I or output means replace O for that we need to check type <block2 type="input">
flack bro help me out for this problem
thank u bro ..!! how to check whether block type is input if it is input we need to place I
No need for the for-each loop
@fpmurphy. Check OP's previous answer. I personally hate for-each, but he had problems with apply-match mechanism.
0

The for-each loop is not necessary i.e.

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="text"/>

    <xsl:variable name="vUpper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
    <xsl:variable name="vLower" select="'abcdefghijklmnopqrstuvwxyz'"/>

    <xsl:template match="//block2[messageType = '103']">
        <xsl:value-of select="concat('CTD,',
           translate(substring(@type, 1, 1), $vLower, $vUpper),
           messageType, messagePriority )"/>
    </xsl:template>

</xsl:stylesheet>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.