0

I have requirement to convert attribute to element but below xslt code is doing it but attribute of child element is within the child element tag along with value but I want attribute values immediately after the child element not within child element.

Xml:

<parent>
<child xml:lang="EN">Value</child>
</parent>

Xslt code:

<xsl:template match="child/@*">
 <xsl:element name="{local-name()}">
 <xsl:value-of select="."/>
 </xsl:element>
 </xsl:template>

After xslt:

<parent>
<child><lang>EN</lang>Value</child>
</parent>

But requirement is:

<parent>
<child>Value</child>
<lang>EN</lang>
</parent>
user8316430
  • 11
  • 1
  • 5
  • So where is the rest of a complete but minimal stylesheet that creates that result? That template you have shown matching `child/@*` will certainly not create the `parent` or `child` element at all. If you want us to fix your code you will have to share the relevant parts, best with a minimal but complete sample. – Martin Honnen Aug 11 '18 at 19:17

1 Answers1

0
<xsl:template match="parent">
       <xsl:element name="parent">
           <xsl:apply-templates select="child"/>
           <xsl:apply-templates select="child/@*"/>
       </xsl:element>
    </xsl:template>
    <xsl:template match="child/@*">
        <xsl:element name="lang">
            <xsl:value-of select="."/>
        </xsl:element>
    </xsl:template>
    <xsl:template match="child">
        <xsl:element name="child">
            <xsl:value-of select="."/>
        </xsl:element>
    </xsl:template>
According to your given xml you can do like this.
imran
  • 461
  • 4
  • 8