You must Sign In to post a response.
  • Category: XML

    How to Re-arrange xml elements using XSLT in C#.


    Are you looking for a way to Re-arrange xml elements using XSLT in C# ? then read this thread to know how to re-arrange it



    Hi,

    This is my sample XSLT file.


    <xsl:for-each select="Projects">
    <xsl:copy-of select="Project_Id"/>
    <xsl:for-each select="FieldDefs">
    <FieldDefs>
    <xsl:copy-of select="FieldDefId"/>
    <FieldDefDescription><xsl:value-of select="FieldDescription"/></FieldDefDescription>
    <xsl:copy-of select="FieldName"/>
    <xsl:copy-of select="FieldPriority"/>
    <xsl:copy-of select="FieldType"/>
    </FieldDefs>
    </xsl:for-each>
    </xsl:for-each>


    In the above example under project section I have project_id. The same Project_Id I need in under FieldDefs section, How to get that.

    My desired output should be in below format.


    <xsl:for-each select="Projects">
    <xsl:for-each select="FieldDefs">
    <FieldDefs>
    <xsl:copy-of select="Project_Id"/>
    <xsl:copy-of select="FieldDefId"/>
    <FieldDefDescription><xsl:value-of select="FieldDescription"/></FieldDefDescription>
    <xsl:copy-of select="FieldName"/>
    <xsl:copy-of select="FieldPriority"/>
    <xsl:copy-of select="FieldType"/>
    </FieldDefs>
    </xsl:for-each>
    </xsl:for-each>


    If any one know this then please guide me.

    Regards,
    Naveen
  • #743870
    Hi Everybody,

    I got the solution by using below sample code.


    <xsl:for-each select="Projects">
    <xsl:variable name="PId" >
    <xsl:value-of select="ProjectId"/>
    </xsl:variable>
    <xsl:for-each select="PageTypeDefsList/PageTypeDefs">
    <PageTypeDefs>
    <Project_Id>
    <xsl:value-of select="$PId"/>
    </Project_Id>
    <xsl:copy-of select="CreateSingleRecor"/>
    <xsl:copy-of select="Description"/>
    <xsl:copy-of select="Page_Type"/>
    </PageTypeDefs>
    </xsl:for-each>
    </xsl:for-each>


    If any one looking for the same then refer this code it will help you to resolve the issue...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments