Topic
1 reply Latest Post - ‏2013-07-03T05:49:00Z by RamyaGullapalli
SystemAdmin
SystemAdmin
76 Posts
ACCEPTED ANSWER

Pinned topic I am facing problem in manipulating XML data with XSLT. please help me out

‏2013-01-18T05:11:49Z |
Dear all,

I am trying to convert an XML with the XSLT . But while iterating the XML file using the <xsl:foreach> tag I am facing the problem and the iteration is not working. below is the code for the same.

My Sample XML is like this which is saved in a XML file.

<BPAddresses>
<row>
<AddressName>Utpal Maity</AddressName>
<Street>street 1</Street>
<Block>street2</Block>
<ZipCode>435453</ZipCode>
<City>Kolkata</City>
<Country>US</Country>
<AddressType>bo_BillTo</AddressType>
<BPCode>W02</BPCode>
<U_WBCUSTADDID>1</U_WBCUSTADDID>
</row>
<row>
<AddressName>Utpal Maity</AddressName>
<Street>street 1</Street>
<Block>street2</Block>
<ZipCode>435453</ZipCode>
<City>Kolkata</City>
<Country>US</Country>
<AddressType>bo_ShipTo</AddressType>
<BPCode>W02</BPCode>
<U_WBCUSTADDID>1</U_WBCUSTADDID>
</row>
</BPAddresses>

And my sample XSLT file is

<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl"
xmlns:env="http://www.w3.org/2003/05/soap-envelope"
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<xsl:variable name="custdetails" select="document('Customer.xml')/node()[1]/node()[2]"/>
<xsl:for-each select="$custdetails/row">
</xsl:for-each>
</xsl:template>
</xsl:transform>

Please give me solution for it.
  • RamyaGullapalli
    RamyaGullapalli
    2 Posts
    ACCEPTED ANSWER

    Re: I am facing problem in manipulating XML data with XSLT. please help me out

    ‏2013-07-03T05:49:00Z  in response to SystemAdmin

    Try this..  for best practice try to avoid for-each use apply-templates instead of that.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">
    <xsl:output method="xml" indent="yes"/>
          
         <xsl:template match="/">
             <xsl:variable name="custdetails" select="document('foreachinput.xml')/BPAddresses"/>
                <xsl:for-each select="$custdetails/row"> 
                    <some><xsl:copy-of select="."/></some>
                </xsl:for-each>
            </xsl:template>
    </xsl:stylesheet>