Trevor Daniel
Trevor Daniel

Reputation: 3954

Converting XML/XSLT to HTML

I have the following XML that came from TNT that I should be able to use to create a shipping label:

https://codebeautify.org/xmlviewer/cb55b98e

I have been supplied with the following XSL file:

https://express.tnt.com/expresswebservices-website/stylesheets/HTMLAddressLabelRenderer.xsl

I have attempted to combine them with the following code:

XmlWriterSettings settings = new XmlWriterSettings
        {
            OmitXmlDeclaration = true,
            ConformanceLevel = ConformanceLevel.Fragment,
            CloseOutput = false,
        };

        // populate the root element with the XML of the address label
        XElement root = new XElement("root", XElement.Parse(await _engine.GetDocument("GET_LABEL", code)));

        XDocument newTree = new XDocument();
        using (XmlWriter writer = XmlWriter.Create(newTree.CreateWriter(), settings))
        {
            XslCompiledTransform xslt = new XslCompiledTransform();
            XsltSettings trev = new XsltSettings
            {
                EnableDocumentFunction = true,
                EnableScript = true
            };
            xslt.Load(@"C:\Users\Trevo\Desktop\HTMLAddressLabelRenderer.xsl", trev, null);

            xslt.Transform(root.CreateReader(), writer);
            writer.Close();
            newTree.Save(@"C:\Users\Trevo\Desktop\result.html");
        }

the HTML only contains the script and head properties and the body is completely empty.

I cannot work out why it isn't working. I have considered that the "root" is not the correct XName but unsure how to work out what it should be.

Any help would be greatly appreciated!

Upvotes: 0

Views: 1010

Answers (1)

ian
ian

Reputation: 94

  1. Try this freeformatter
  1. For XML Input, on the first line, enter the below xml, then paste your xml code
<?xml version="1.0"?>
  1. For XML Output, just paste your xsl code.

  2. Click Transform XML. Just play around with the formatter but it will give html output.

Upvotes: 1

Related Questions