Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

XML Transform using XSLT when simple type is repeating

$
0
0

Hi,

I am trying to transform one xml to another xml using xslt transform.
when there is a complex node repeating then all nodes are properly transformed and things are fine.
If the simple type is repeating then same count of nodes are transformed but value of all nodes are value of the very first node.

This is a part of xml

    <GetDataResult xmlns="http://tempuri.org/">
        <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">0</string>
        <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">1</string>
        <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">2</string>
        <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">3</string>
    </GetDataResult>


this is my Xslt snippet part

    <response>
        <xsl:for-each select="ns1:GetDataResponse/ns1:GetDataResult/ns2:string" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
            <item>
                <xsl:value-of select="/ns1:GetDataResponse/ns1:GetDataResult/ns2:string/text()" />
            </item>
        </xsl:for-each>
    </response>

i tried few combinations of Xslt for each loop, however the final result is as below. all the items have value of the first repeating node.

    <?xml version="1.0" encoding="utf-16"?>
    <Fields>
        <response>
            <item>0</item>
            <item>0</item>
            <item>0</item>
            <item>0</item>
        </response>
    </Fields>

this it transformation code snippet.

        XmlDocument xslDoc = new XmlDocument();
        xslDoc.InnerXml = XsltCode;
        System.Xml.Xsl.XslTransform xslTransform = new System.Xml.Xsl.XslTransform();
        StringWriter xmlResult = new StringWriter();
        try
        {
            //Load XSL Transform Object
            xslTransform.Load(xslDoc, new XmlUrlResolver(), null);
            //Load the xsl parameter if Any
            System.Xml.Xsl.XsltArgumentList xslArgs = new System.Xml.Xsl.XsltArgumentList();
            //Call the actual Transform method
            xslTransform.Transform(xmlDoc, null, xmlResult, new XmlUrlResolver());
        }
        catch
        { }
        string firstParse = xmlResult.ToString();

Regards,

 Harish


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>