I have a requirement where i have to convert using xslt, known tags to be replaced, but for any non-identified tags should be put inside a property bag (like in c#) kind of mode. For example. I want to convert the below XML:
<Envelope>
<body>
<MyOperation_reply_data>
<operation_name>1211</operation_name>
<operation_short_desc>SCAMA</operation_short_desc>
<operation_long_desc>C4 SCAM PIECE PART ASSEMBLY
</operation_long_desc>
<primary_units>UNITS</primary_units>
<firstAttribute>123</firstAttribute>
<sampleone>554</sampleone>
<area>newarea</area>
<group>samplegroup</group>
<whatever>uuu</whatever>
</MyOperation_reply_data>
</body>
</Envelope>
To this format:
<Envelope>
<Body>
<OperationInfo OperationName="MyOperation">
<OperationData>
<Operation>MyOperation</Operation>
<ShortDescription>MyDescription</ShortDescription>
<LongDescription>MyLongDescription</LongDescription>
<PrimaryUnits>UNITS</PrimaryUnits>
<Attributes>
<Attribute Name="firstAttribute" Value="123" />
<Attribute Name="sampleone" Value="554" />
<Attribute Name="area" Value="newarea" />
<Attribute Name="group" Value="samplegroup" />
<Attribute Name="whatever" Value="uuu" />
</Attributes>
</OperationData>
</OperationInfo>
</Body>
As you could see only the operation, operation long/shortdescription and primaryunits are the recognized tags. anything else i would want to put it in the Attributes list like above. The “other” tags list could grow – so the idea is to put all those other tags into this property bag kind of mode.
the challenge I have is that i am unable to do for-each or identify the “other” tags. I tried selected not(self:: with or statements but didn’t help much.
In XSLT 1.0 you can use
xsl:keyto create a “white list” of elements.XML Input
XSLT 1.0
XML Output