I need to convert all my attributes in the xml to elements with some conditions. Say for example some attributes should be prefixed with the "Value" to it. I achieved this far. Along with this I need to change my namespace also. I couldn't achieve that.
XML
<Template xmlns="styling/1.0.0" Name="TemplateFromDictionary">
<Style Name="Default">
<Fill Color=""/>
<Stroke Color="0000FF" LineStyle="Single" Width="1"/>
<Symbol Color="FFFFFF" Name="default.png" ScaleX="100" ScaleY="100" ScaleMode="Drawing"/>
</Style>
<Style Name="Parcel">
<Fill Color="48F5F5F5"/>
<Stroke Color="C0C0C0" LineStyle="Single" Width="1"/>
<Symbol Color="FFFFFF" Name="default.png" ScaleX="100" ScaleY="100" ScaleMode="Drawing"/>
</Style>
</Template>
XSLT
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"
xmlns:s="styling/1.0.0"
xmlns="styling/1.0.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="s:Style|s:Template">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:variable name="name">
<xsl:apply-templates select="." mode="name"/>
</xsl:variable>
<xsl:element name="{$name}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="@Color|@Width|@ScaleX|@ScaleY|@LeftIndent|@RightIndent|@FirstLineIndent|@SpaceBefore|@SpaceAfter|@Size" mode="name">
<xsl:value-of select="concat(name(), 'Value')"/>
</xsl:template>
<xsl:template match="@*" mode="name">
<xsl:value-of select="name()"/>
</xsl:template>
</xsl:stylesheet>
OUTPUT
<?xml version="1.0" encoding="utf-8"?>
<Template Name="TemplateFromDictionary" xmlns="styling/1.0.0">
<Style Name="Default">
<Fill>
<ColorValue></ColorValue>
</Fill>
<Stroke>
<ColorValue>0000FF</ColorValue>
<LineStyle>Single</LineStyle>
<WidthValue>1</WidthValue>
</Stroke>
<Symbol>
<ColorValue>FFFFFF</ColorValue>
<Name>default.png</Name>
<ScaleXValue>100</ScaleXValue>
<ScaleYValue>100</ScaleYValue>
<ScaleMode>Drawing</ScaleMode>
</Symbol>
</Style>
<Style Name="Parcel">
<Fill>
<ColorValue>48F5F5F5</ColorValue>
</Fill>
<Stroke>
<ColorValue>C0C0C0</ColorValue>
<LineStyle>Single</LineStyle>
<WidthValue>1</WidthValue>
</Stroke>
<Symbol>
<ColorValue>FFFFFF</ColorValue>
<Name>default.png</Name>
<ScaleXValue>100</ScaleXValue>
<ScaleYValue>100</ScaleYValue>
<ScaleMode>Drawing</ScaleMode>
</Symbol>
</Style>
</Template>
In output instead of this
<Template Name="TemplateFromDictionary" xmlns="styling/1.0.0">
I need this
<Template Name="TemplateFromDictionary" xmlns="styling/2.0.0">
I tried by changing the namespace in xslt to xmlns="styling/2.0.0" But this is giving the results like
<Fill><ColorValue xmlns="styling/2.0.0"></ColorValue></Fill>
The namespace is embedded into all elements and the Template element looks the same
<Template Name="TemplateFromDictionary" xmlns="styling/1.0.0">
I need the output exactly same as the output mentioned above only that namespace in Template element needs to be changed.
I am transforming this with C#.
Please help me on this.