Hi,
I am have below input xml, I want to remove special characters from all nodes through xslt, please help me
Janpath-Building 1 & 2, near Western Court, Janpath, New Delhi, Delhi-110001
C-56, G Block BKC, Bandra Kurla Complex, Bandra East, Mumbai, Maharashtra 400098
Loading
Rajkiran SwainPosted May 5, 2023, 4:05 PM
You can use XSLT to remove special characters from all nodes in your input XML by creating a template that matches all nodes and applies a regular expression to remove the unwanted characters. Here's an example XSLT stylesheet that does this:
```
```
This XSLT stylesheet defines two templates. The first template matches all text nodes and applies the `translate()` function to remove the special characters '&', '<', '>', and '"'. The second template matches all other nodes and copies them as-is using the `xsl:copy` element.
To apply this XSLT stylesheet to your input XML, you can use an XSLT processor such as the one built into the .NET Framework or an online tool such as https://xsltfiddle.liberty-development.net/. Here's an example of how to use the .NET Framework's XslCompiledTransform class to apply the stylesheet:
```
// Load the input XML document
XmlDocument doc = new XmlDocument();
doc.Load("input.xml");
// Load the XSLT stylesheet
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("stylesheet.xslt");
// Create an XmlWriter to output the transformed XML
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter writer = XmlWriter.Create("output.xml", settings);
// Apply the stylesheet to the input XML and write the transformed output
xslt.Transform(doc, writer);
// Close the writer
writer.Close();
```
In this example, the input XML is loaded from a file called "input.xml", and the XSLT stylesheet is loaded from a file called "stylesheet.xslt". The transformed output is written to a file called "output.xml". You can modify the file paths as necessary for your own use case.
AniPosted May 8, 2023, 9:09 AM
Thanks Rajkiran Swain
AniPosted May 5, 2023, 3:59 PM
Thanks for the response, but I need the xslt transform, which will remove special characters from all xml nodes.
Please let me know how to achieve this requirement
Rajkiran SwainPosted May 5, 2023, 2:53 PM