Reputation: 1994
I want to convert all child node as attribute name to Nodes. and attribute value should be the node value.
How do i give dynamic node name?
<xsl:attribute name="shouldBeNodeName">
SOURCE XML
<transaction>
<transactionId>T001</transactionId>
<clientId>C001</clientId>
<contractId>C001</contractId>
<scriptId>REL</scriptId>
<price>500.5000</price>
<tradeDate>2019-02-09 16:00:00</tradeDate>
<valueDate>2019-02-09 16:00:00</valueDate>
<quantity>100000</quantity>
</transaction>
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<ROOT>
<TRANS>
<xsl:for-each select="node()/*">
<xsl:attribute name="shouldBeNodeName">
<!-- <xsl:value-of select="name()" /> -->
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
</TRANS>
</ROOT>
</xsl:template>
</xsl:stylesheet>
Upvotes: 0
Views: 61
Reputation: 1994
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<ROOT>
<TRANS>
<xsl:for-each select="node()/*">
<xsl:attribute name="{name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
</TRANS>
</ROOT>
</xsl:template>
Upvotes: 0