• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

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
0
ersldublin
Asked:
ersldublin
  • 2
  • 2
1 Solution
 
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
 
Geert BormansCommented:

<?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
 
ersldublinAuthor Commented:
Excellent

Thanks kindly does just what i need.
0
 
Geert BormansCommented:
welcome
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now