XML to XML using XSL

Hi

I am trying to transform an xml file like


<TestData Name="TestData" Value="">
   <Value1 Name="Value1" Value="100" />
  <Value2 Name="Value2" Value="200" />
  <Value3 Name="Value3" Value="300" />
   <Value4 Name="Value4" Value="">
         <Value4_1 Name="Value4_1" Value="400" />
   </Value4>
<TestData>

To

<TestData>
   <Value1>100</Value1>
   <Value2>200</Value2>
   <Value3>300</Value3>
   <Value4>
        <Value4_1>400</Value4_1>
   </Value4>
<TestData>

the one thing i cant seem to figure out is how to set the elements text to the value of the attribute 'Value'.

Any assistance would be greatly appreciated.
Cheers
Phil
ersldublinAsked:
Who is Participating?
 
Geert BormansConnect With a Mentor Information ArchitectCommented:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:choose>
                <xsl:when test="*">
                    <xsl:apply-templates select="node()"/>
                </xsl:when>
                <xsl:when test="@Value">
                    <xsl:value-of select="@Value"/>
                </xsl:when>
            </xsl:choose>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
käµfm³d 👽Commented:
Which do you need help with:  the C# code, or the XSL code?
0
 
ersldublinAuthor Commented:
i meant to put this in the XML zome - I cant see a way to remove this from the C# zone.

But yes I'm looking for the XSL code advise on this

Cheers
0
 
ersldublinAuthor Commented:
Excellent

Thanks kindly does just what i need.
0
 
Geert BormansInformation ArchitectCommented:
welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.