0

I have a xml string that contains linked stylesheet:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet href="https://express.tnt.com/expresswebservices-website/stylesheets/HTMLManifestRenderer.xsl" type="text/xsl"?>
<CONSIGNMENTBATCH><BARCODEURL>/barbecue/barcode?type=code39&amp;height=70&amp;width=1&amp;data=</BARCODEURL><HOST>https://express.tnt.com</HOST><IMAGESDIR>/expresswebservices-website/rendering/images</IMAGESDIR><CONSIGNMENT originCountry="SK" marketType="INTERNATIONAL"><HEADER><SHIPMENTDATE>21/01/2021</SHIPMENTDATE><SENDER><COMPANYNAME><![CDATA[Sender & TEST DO NOT COLLECT C]]></COMPANYNAME><STREETADDRESS1><![CDATA[TNT Express]]></STREETADDRESS1><CITY><![CDATA[Bratislava]]></CITY><POSTCODE>821 05</POSTCODE><COUNTRY>SLOVAKIA</COUNTRY><CONTACTNAME><![CDATA[Mr Contact]]></CONTACTNAME><CONTACTDIALCODE>01827</CONTACTDIALCODE><CONTACTTELEPHONE>aaaa</CONTACTTELEPHONE><CONTACTEMAIL>[email protected]</CONTACTEMAIL><ACCOUNT>1111</ACCOUNT></SENDER><COLLECTION><COMPANYNAME><![CDATA[Sender & TEST DO NOT COLLECT C]]></COMPANYNAME><STREETADDRESS1><![CDATA[TNT Express]]></STREETADDRESS1><CITY><![CDATA[Bratislava]]></CITY><POSTCODE>821 05</POSTCODE><COUNTRY>SLOVAKIA</COUNTRY><CONTACTNAME><![CDATA[Mr Contact]]></CONTACTNAME><CONTACTDIALCODE>01827</CONTACTDIALCODE><CONTACTTELEPHONE>aaaa</CONTACTTELEPHONE><CONTACTEMAIL>[email protected]</CONTACTEMAIL></COLLECTION><CARRIAGEFORWARD>N</CARRIAGEFORWARD></HEADER><RECEIVER><COMPANYNAME><![CDATA[Receiver Company Name]]></COMPANYNAME><STREETADDRESS1><![CDATA[TEST DO NOT COLLECT]]></STREETADDRESS1><CITY><![CDATA[Hoofddorp]]></CITY><POSTCODE>2132 LS</POSTCODE><COUNTRY>NETHERLANDS</COUNTRY><CONTACTNAME><![CDATA[Mr. Contact]]></CONTACTNAME><CONTACTDIALCODE>01827</CONTACTDIALCODE><CONTACTTELEPHONE>717733</CONTACTTELEPHONE><CONTACTEMAIL>[email protected]</CONTACTEMAIL></RECEIVER><DELIVERY><COMPANYNAME><![CDATA[Delivery Company Name]]></COMPANYNAME><STREETADDRESS1><![CDATA[TEST DO NOT COLLECT]]></STREETADDRESS1><CITY><![CDATA[Hoofddorp]]></CITY><POSTCODE>2132 LS</POSTCODE><COUNTRY>NETHERLANDS</COUNTRY><CONTACTNAME><![CDATA[Mr. Contact]]></CONTACTNAME><CONTACTDIALCODE>01827</CONTACTDIALCODE><CONTACTTELEPHONE>717733</CONTACTTELEPHONE><CONTACTEMAIL>[email protected]</CONTACTEMAIL></DELIVERY><TOTALVOLUME units="m3">0.027</TOTALVOLUME><TOTALWEIGHT units="kg">1.80</TOTALWEIGHT><CUSTOMERREF><![CDATA[Customer supplied ref]]></CUSTOMERREF><CONSIGNMENTTYPE>N</CONSIGNMENTTYPE><CONNUMBER>GE422634139SK</CONNUMBER><SERVICE>15N Express</SERVICE><INSURANCEVALUE>150.00</INSURANCEVALUE><TOTALITEMS>3</TOTALITEMS><GOODSVALUE>180.00</GOODSVALUE><OPTION1></OPTION1><OPTION2></OPTION2><OPTION3></OPTION3><OPTION4></OPTION4><OPTION5></OPTION5><DANGEROUSGOODS>N</DANGEROUSGOODS><CURRENCY>EUR</CURRENCY><INSURANCECURRENCY>EUR</INSURANCECURRENCY><PAYMENTIND>S</PAYMENTIND><CONREF>TESTREF1</CONREF><PACKAGE><GOODSDESC>box 1</GOODSDESC><LENGTH units="cm">10.0</LENGTH><HEIGHT units="cm">30.0</HEIGHT><WIDTH units="cm">30.0</WIDTH><WEIGHT units="Kg">0.6</WEIGHT><ITEMS>3</ITEMS><VOLUME units="m3">0.027</VOLUME><PACKAGEINDEX>1</PACKAGEINDEX><PACKAGEMAX>1</PACKAGEMAX><ARTICLE><PACKAGECODE>6131779</PACKAGECODE><INVOICEDESC><![CDATA[metal paperclips]]></INVOICEDESC><INVOICEVALUE>90</INVOICEVALUE><ITEMS>1</ITEMS><DESCRIPTION><![CDATA[paperclips]]></DESCRIPTION><WEIGHT units="Kg">0.6</WEIGHT><HTS>~</HTS><ORIGINCOUNTRY>~</ORIGINCOUNTRY></ARTICLE><PREVIOUSPACKAGEITEMCOUNT>0</PREVIOUSPACKAGEITEMCOUNT></PACKAGE><INVOICENUMBER></INVOICENUMBER><PURCHASEORDERNUMBER></PURCHASEORDERNUMBER><INCOTERMS></INCOTERMS><DISCOUNT>0</DISCOUNT><INSURANCECHARGES>0</INSURANCECHARGES><FREIGHTCHARGES>0</FREIGHTCHARGES><OTHERCHARGES>0</OTHERCHARGES><INVOICETOTAL>0</INVOICETOTAL></CONSIGNMENT></CONSIGNMENTBATCH>

How do I transform it using the linked stylesheet? Please note, that the stylesheet url might vary at runtime

Following attempt ends with System.Xml.XmlException: Resolving of external URIs was prohibited

var myXslTrans = new XslCompiledTransform();
myXslTrans.Load("https://express.tnt.com/expresswebservices-website/stylesheets/HTMLManifestRenderer.xsl", 
    new XsltSettings(true, true), new XmlUrlResolver { });
XmlReader xmlReader = XmlReader.Create(new StringReader(manifestXml), new XmlReaderSettings
{
   
});
var htmlWriter = new StringWriter();
myXslTrans.Transform(xmlReader, null, htmlWriter);
2
  • 1
    I think this is a breaking change in .NET core, someone run into it previously and posted a solution in stackoverflow.com/a/61490828/252228 to set AppContext.SetSwitch("Switch.System.Xml.AllowDefaultResolver", true); Commented Jan 21, 2021 at 21:53
  • Yep, you're right, it helped. Do you want to post an answer? Commented Jan 22, 2021 at 7:41

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.