I asked about this, and Jamie Santos helped me with this decision.
I already used Convert XML to HTML TBB , but this did not work because the closing tag was already placed in the output variable.
So, in the next TBB, the Schema [Tags] parameter is used, where we pass the list of tags (Comma Separated) that we want to change the closing tag itself (for example, / ">) with a closing tag (for example)
[TcmTemplateTitle("Remove Selft Closing Tag")] public class RemoveSelfClosingTag : ITemplate { public override void Transform(Engine engine, Package package) { var outputItem = package.GetByName(Package.OutputName);
//if not Output in package, return if (outputItem == null) return; var output = outputItem.GetAsString(); var tagsCsv = package.GetValue("Tags"); //TBB parameter [tags using CSV] : 'iframe' if (string.IsNullOrEmpty(tagsCsv)) return; var tags = tagsCsv.Split(','); foreach (var tag in tags) { RemoveSelftTag(tag, ref output); } outputItem.SetAsString(output); } //ref because string is immutable. private void RemoveSelftTag(string tagName, ref string output) { var pattern = string.Format("(?'fistPart'<(?'tag'{0})[^>]+?)/>", tagName); output = Regex.Replace(output, pattern, @"${fistPart}></${tag}>"); } }
code>
source share