Hi All,


I have the attached xml and xsl, xml being the input to the xsl. The xml contains two account numbers and the xsl will print the account numbers.
Now what we need is, number of variables equal to no: of account numbers in the xml, to be declared in the xsl. Then use those variables to print the account numbers. Example, for the attached xml, in the xsl, we may have dynaReq1 containing first account number and dynaReq2 containg second account number and then use these two variables to print the accounts. In case we have three account numbers, there should be three variables holding the information. Please let us know how to do this as we have a requirement for holding the accountnumbers in different variables.

You have a problem with namespace
to find the tag with a V12, the name in the xslt to be performed

if the namespace does not then delete xslt


xml

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.americanexpress.com/informationservice/service/ICS/CustomerService/v1/" xmlns:v11="http://www.americanexpress.com/schema/ICS/GlobalData/v1/" xmlns:v12="http://www.americanexpress.com/informationservice/schema/ICS/CustomerService/v1/">
    <soapenv:Header>
        <v1:RequestHeader>
            <v11:correlationID>Corr12345678912345678912</v11:correlationID>
            <v11:userId>Rejeesh</v11:userId>
            <v11:sORRegionToken>
                <v11:automationID></v11:automationID>
                <v11:sORRegionID></v11:sORRegionID>
            </v11:sORRegionToken>
        </v1:RequestHeader>
    </soapenv:Header>
    <soapenv:Body>
        <v1:CustomerServicegetCustomerInfoRequest1>
            <v12:getCustomerInfoParameters>
                <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
                <v12:customerInfoSearchKey>
                    <v12:cardNO>123456789</v12:cardNO>
                </v12:customerInfoSearchKey>
                <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
            </v12:getCustomerInfoParameters>
            <v12:getCustomerInfoParameters>
                <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
                <v12:customerInfoSearchKey>
                    <v12:cardNO>34567890</v12:cardNO>
                </v12:customerInfoSearchKey>
                <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
            </v12:getCustomerInfoParameters>
        </v1:CustomerServicegetCustomerInfoRequest1>
    </soapenv:Body>
</soapenv:Envelope>

xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:v1="http://www.americanexpress.com/informationservice/service/ICS/CustomerService/v1/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                xmlns:v12="http://www.americanexpress.com/informationservice/schema/ICS/CustomerService/v1/" exclude-result-prefixes="v1 v12 soapenv">
	<xsl:output method="xml" indent="yes"/>
	<xsl:template match="/">
		<info>
			<xsl:apply-templates select="soapenv:Envelope/soapenv:Body/v1:CustomerServicegetCustomerInfoRequest1"/>
		</info>
	</xsl:template>


	<xsl:template match="v1:CustomerServicegetCustomerInfoRequest1">
		<xsl:apply-templates select="v12:getCustomerInfoParameters"/>
	</xsl:template>



	<xsl:template match="v12:getCustomerInfoParameters">
		<xsl:apply-templates select="v12:customerInfoSearchKey/v12:cardNO"/>
	</xsl:template>


	<xsl:template match="v12:cardNO">
		<!-- your way
		<xsl:variable name="cno">			
				<xsl:value-of select="concat('&#xA;&lt;cardNo&gt;',.,'&lt;/cardNo&gt;')"/>			
		</xsl:variable>
		-->
		<cardNo>
			<xsl:value-of select="."/>
		</cardNo>
		<!-- your way
		<xsl:value-of select="$cno" disable-output-escaping="yes"/>
		-->
	</xsl:template>
</xsl:stylesheet>

result

<?xml version='1.0' ?>
<info>
  <cardNo>123456789</cardNo>
  <cardNo>34567890</cardNo>
</info>

Hi,

Thanks for the response. However, in the above case also, we can have only one variable, cno, which has the last card no: node's data. What we need is, in this case, for example, variable cno1 holding 123456789 and variable cno2 holding 34567890.

If we have three card no, in the input xml, we should have one more variable cno3, holding the third card no: nodes data. Is this possible? Based on the no: of input nodes, the no: of variables also change? The maximum no: of account numbers that can come is fifteen.

you can use position() and predicate to selcet the cardNo

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:v1="http://www.americanexpress.com/informationservice/service/ICS/CustomerService/v1/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                xmlns:v12="http://www.americanexpress.com/informationservice/schema/ICS/CustomerService/v1/" exclude-result-prefixes="v1 v12 soapenv">
	<xsl:output method="xml" indent="yes"/>
	<xsl:template match="/">
		<result>
			<xsl:apply-templates select="soapenv:Envelope/soapenv:Body/v1:CustomerServicegetCustomerInfoRequest1"/>
		</result>
	</xsl:template>
	<xsl:template match="v1:CustomerServicegetCustomerInfoRequest1">
		<count>
			<xsl:value-of select="count(//v12:cardNO)"/>
		</count>
		<!--display all cardNO -->
		<xsl:apply-templates select="v12:getCustomerInfoParameters/v12:customerInfoSearchKey/v12:cardNO"/>
		<!-- display cardNO 1 -->
		<choose>
			<xsl:value-of select="v12:getCustomerInfoParameters/v12:customerInfoSearchKey/v12:cardNO[1]"/>
		</choose>
		<!-- display cardNo 3 result a empty tag choose 
		     you can tested with xsl:if -->
		<choose>
			<xsl:value-of select="v12:getCustomerInfoParameters/v12:customerInfoSearchKey/v12:cardNO[3]"/>
		</choose>
		<xsl:for-each select="v12:getCustomerInfoParameters/v12:customerInfoSearchKey/v12:cardNO">
			<xsl:element name="for{position()}">
			<xsl:value-of select="."/>
			</xsl:element>
			<!-- not working 
			<xsl:variable name="for{position()}">
			<xsl:value-of select="."/>
			</xsl:variable>
			-->
		</xsl:for-each>


	</xsl:template>
	<xsl:template match="v12:cardNO">
		<item>
			<xsl:value-of select="concat(position(),'  ',.)"/>
		</item>
	</xsl:template>
</xsl:stylesheet>

result

<?xml version='1.0' ?>
<result>
  <count>2</count>
  <item>1  123456789</item>
  <item>2  34567890</item>
  <choose>123456789</choose>
  <choose/>
  <for1>123456789</for1>
  <for2>34567890</for2>
</result>

Helmut,

Thanks. I would like to eliminate the usage of 'foreach' in the below xsl. The output should be url1url2, because we have two card numbers in the input request(which is the case, same xml as above). The variable request-targets should have 'url1url2'

The things we want to do is
eliminate the usage of foreach(I saw in one of your posts to avoid foreach as much we can)
issue we are facing is, the variable request-A/request-B cannot be used outside for each. Could you please help

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:v1="http://www.americanexpress.com/informationservice/service/ICS/CustomerService/v1/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                xmlns:v12="http://www.americanexpress.com/informationservice/schema/ICS/CustomerService/v1/" exclude-result-prefixes="v1 v12 soapenv"> 
    
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
        <xsl:for-each select="//*/*/*/*[local-name()='getCustomerInfoParameters']">

            <xsl:if test="position() = 1" >
                <xsl:variable name="request-A">
                    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.americanexpress.com/informationservice/service/ICS/CustomerService/v1/" xmlns:v11="http://www.americanexpress.com/schema/ICS/GlobalData/v1/" xmlns:v12="http://www.americanexpress.com/informationservice/schema/ICS/CustomerService/v1/">
                        <soapenv:Header>
                            <v1:RequestHeader>
                                <v11:correlationID>Corr12345678912345678912</v11:correlationID>
                                <v11:userId>Rejeesh</v11:userId>
                                <v11:sORRegionToken>
                                    <v11:automationID/>
                                    <v11:sORRegionID/>
                                </v11:sORRegionToken>
                            </v1:RequestHeader>
                        </soapenv:Header>
                        <soapenv:Body wsu:Id="id-35" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                            <v1:CustomerServicegetCustomerInfoRequest1>
                                <v12:getCustomerInfoParameters>
                                    <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
                                    <v12:customerInfoSearchKey>
                                        <v12:cardNO>
                                            <xsl:value-of select="*/*[local-name()='cardNO']"/>
                                        </v12:cardNO>
                                    </v12:customerInfoSearchKey>
                                    <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
                                </v12:getCustomerInfoParameters>
                            </v1:CustomerServicegetCustomerInfoRequest1>
                        </soapenv:Body>
                    </soapenv:Envelope>
                </xsl:variable>
                
            </xsl:if>
            <xsl:if test="position() = 2" >
                <xsl:variable name="request-B">
                    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.americanexpress.com/informationservice/service/ICS/CustomerService/v1/" xmlns:v11="http://www.americanexpress.com/schema/ICS/GlobalData/v1/" xmlns:v12="http://www.americanexpress.com/informationservice/schema/ICS/CustomerService/v1/">
                        <soapenv:Header>
                            <v1:RequestHeader>
                                <v11:correlationID>Corr12345678912345678912</v11:correlationID>
                                <v11:userId>Rejeesh</v11:userId>
                                <v11:sORRegionToken>
                                    <v11:automationID/>
                                    <v11:sORRegionID/>
                                </v11:sORRegionToken>
                            </v1:RequestHeader>
                        </soapenv:Header>
                        <soapenv:Body wsu:Id="id-35" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                            <v1:CustomerServicegetCustomerInfoRequest1>
                                <v12:getCustomerInfoParameters>
                                    <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
                                    <v12:customerInfoSearchKey>
                                        <v12:cardNO>
                                            <xsl:value-of select="*/*[local-name()='cardNO']"/>
                                        </v12:cardNO>
                                    </v12:customerInfoSearchKey>
                                    <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
                                </v12:getCustomerInfoParameters>
                            </v1:CustomerServicegetCustomerInfoRequest1>
                        </soapenv:Body>
                    </soapenv:Envelope>
                </xsl:variable>
                
            </xsl:if>
        </xsl:for-each>         

        <xsl:variable name="request-targets">
           
                <xsl:if test="$request-A">
                    <url input="multi-request-A">url1</url>
                </xsl:if>
            <xsl:if test="$request-B">
                <url input="multi-request-B">url2</url>
            </xsl:if>
                
        </xsl:variable>

        
        <xsl:value-of select="$request-targets" />
    </xsl:template>

</xsl:stylesheet>

I got it. Never mind

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.