简体   繁体   中英

Search Replace value in XML using XSLT

I am new in XSLT and need some help, I am getting an Original XML below which I need to transform as a Transformed XML

Original

<?xml version="1.0" encoding="UTF-8"?>
<cXML payloadID="121" timestamp="2022-09-12" version="1.2.031" xml:lang="en-US">
<Header>
<From>
<Login domain="RollID">
<Value>ABC12100</Value>
</Login>
<Login domain="NameID">
<Value>BOB</Value>
</Login>
<Login domain="CourseID">
<Value>Default</Value>
</Login>
</From>
<Header>
<OrderID>
<OrderHeaderID sampleID="sdhjgwsd" orderDate="TEST-2022-09-12T21:30:31+02:00" orderID="66625" orderType="regular" orderVersion="1" type="new">
</OrderID>
</cXML>

Transformed XML

<?xml version="1.0" encoding="UTF-8"?>
<cXML payloadID="121" timestamp="2022-09-12" version="1.2.031" xml:lang="en-US">
<Header>
<From>
<Login domain="RollID">
<Value>ABC12100_TEST</Value>
</Login>
<Login domain="NameID">
<Value>BOB</Value>
</Login>
<Login domain="CourseID">
<Value>Default</Value>
</Login>
</From>
<Header>
<OrderID>
<OrderHeaderID sampleID="sdhjgwsd" orderDate="2022-09-12T21:30:31+02:00" orderID="66625_**TEST**" orderType="regular" orderVersion="1" type="new">
</OrderID>
</cXML>

I need value of OrderId and cXML/Header/From/Login[@domain='RollID']/ Value to be appended with TEST as mentioned in transform XML. Please help !!

Write a transformation using the identity template to copy everything unchanged, plus a template to transform the selected attributes

<xsl:template match="@orderID">
  <xsl:attribute name="orderID"><xsl:value-of select="."/>_**TEST**</xsl:attribute>
</xsl:template>

This question does feel rather as if you're launching into using XSLT without having first done some reading. A few hours spent with a book or tutorial would be a good investment of your time.

Also, it's always a good idea in XSLT questions to say whether you're using 1.0, 2.0, or 3.0, since all are in widespread use, and the answers will often vary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM