提问人:amit nindroda 提问时间:1/26/2018 最后编辑:Professor Abronsiusamit nindroda 更新时间:1/26/2018 访问量:221
使用 XSL 样式表将 XML 显示为可视格式的问题
issue with display xml as visual format using xsl stylesheet
问:
您好,我正在使用 XML 格式获取 curl 响应来编写 xml 文件。它已经将样式表包含在 .xsl 格式中,但是当我在浏览器中打开 XML 时,它没有显示为视觉样式格式。请参阅下面是我在XML文件中编写的XML内容。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet href="https://express.tnt.com/expresswebservices-website/stylesheets/HTMLConsignmentNoteRenderer.xsl" type="text/xsl"?>
<CONSIGNMENTBATCH>
<BARCODEURL>/barbecue/barcode?type=code39&height=70&width=1&data=</BARCODEURL>
<HOST>https://express.tnt.com</HOST>
<IMAGESDIR>/expresswebservices-website/rendering/images</IMAGESDIR>
<CONSIGNMENT originCountry="AU" marketType="INTERNATIONAL">
<HEADER last="true">
<SHIPMENTDATE>29/01/2018</SHIPMENTDATE>
<SENDER>
<COMPANYNAME><![CDATA[Sender Co 01-008]]></COMPANYNAME>
<STREETADDRESS1><![CDATA[TEST DO NOT COLLECT1]]></STREETADDRESS1>
<STREETADDRESS2><![CDATA[TEST DO NOT COLLECT2]]></STREETADDRESS2>
<STREETADDRESS3><![CDATA[TEST DO NOT COLLECT3]]></STREETADDRESS3>
<CITY><![CDATA[Hoppers Crossing]]></CITY>
<POSTCODE>3029</POSTCODE>
<COUNTRY>AUSTRALIA</COUNTRY>
<CONTACTNAME><![CDATA[Mr Contact]]></CONTACTNAME>
<CONTACTDIALCODE>01827</CONTACTDIALCODE>
<CONTACTTELEPHONE>717733</CONTACTTELEPHONE>
<CONTACTEMAIL>[email protected]</CONTACTEMAIL>
<ACCOUNT>30017823</ACCOUNT>
</SENDER>
<COLLECTION>
<COMPANYNAME><![CDATA[Collection Name]]></COMPANYNAME>
<STREETADDRESS1><![CDATA[TEST DO NOT COLLECT4]]></STREETADDRESS1>
<STREETADDRESS2><![CDATA[TEST DO NOT COLLECT5]]></STREETADDRESS2>
<STREETADDRESS3><![CDATA[TEST DO NOT COLLECT6]]></STREETADDRESS3>
<CITY><![CDATA[Hoppers Crossing]]></CITY>
<POSTCODE>3029</POSTCODE>
<COUNTRY>AUSTRALIA</COUNTRY>
<CONTACTNAME><![CDATA[Mr Contact]]></CONTACTNAME>
<CONTACTDIALCODE>00000</CONTACTDIALCODE>
<CONTACTTELEPHONE>700005</CONTACTTELEPHONE>
<CONTACTEMAIL>[email protected]</CONTACTEMAIL>
</COLLECTION>
<CARRIAGEFORWARD>N</CARRIAGEFORWARD>
</HEADER>
<RECEIVER>
<COMPANYNAME><![CDATA[Receiver Name]]></COMPANYNAME>
<STREETADDRESS1><![CDATA[TEST DO NOT COLLECT7]]></STREETADDRESS1>
<STREETADDRESS2><![CDATA[TEST DO NOT COLLECT8]]></STREETADDRESS2>
<STREETADDRESS3><![CDATA[TEST DO NOT COLLECT9]]></STREETADDRESS3>
<CITY><![CDATA[Amsterdam]]></CITY>
<POSTCODE>1100 AA</POSTCODE>
<COUNTRY>NETHERLANDS</COUNTRY>
<CONTACTNAME><![CDATA[Mr Frank]]></CONTACTNAME>
<CONTACTDIALCODE>1672</CONTACTDIALCODE>
<CONTACTTELEPHONE>987432</CONTACTTELEPHONE>
<CONTACTEMAIL>[email protected]</CONTACTEMAIL>
<VAT>7668880</VAT>
</RECEIVER>
<DELIVERY>
<COMPANYNAME><![CDATA[Delivery Name]]></COMPANYNAME>
<STREETADDRESS1><![CDATA[TEST DO NOT COLLECT10]]></STREETADDRESS1>
<STREETADDRESS2><![CDATA[TEST DO NOT COLLECT11]]></STREETADDRESS2>
<STREETADDRESS3><![CDATA[TEST DO NOT COLLECT12]]></STREETADDRESS3>
<CITY><![CDATA[Amsterdam]]></CITY>
<POSTCODE>1100 AA</POSTCODE>
<COUNTRY>NETHERLANDS</COUNTRY>
<CONTACTNAME><![CDATA[Mr Frank]]></CONTACTNAME>
<CONTACTDIALCODE>1672</CONTACTDIALCODE>
<CONTACTTELEPHONE>987432</CONTACTTELEPHONE>
<CONTACTEMAIL>[email protected]</CONTACTEMAIL>
<VAT>7668880</VAT>
</DELIVERY>
<TOTALVOLUME units="m3">0.649</TOTALVOLUME>
<TOTALWEIGHT units="kg">3.60</TOTALWEIGHT>
<CUSTOMERREF><![CDATA[DISKS]]></CUSTOMERREF>
<CONSIGNMENTTYPE>N</CONSIGNMENTTYPE>
<CONNUMBER>GE161714365AU</CONNUMBER>
<SERVICE>48N Economy Express</SERVICE>
<INSURANCEVALUE>150.00</INSURANCEVALUE>
<GOODSDESC1><![CDATA[assorted office accessories]]></GOODSDESC1>
<TOTALITEMS>6</TOTALITEMS>
<GOODSVALUE>180.00</GOODSVALUE>
<DELIVERYINST><![CDATA[Delivery Instructions TEST]]></DELIVERYINST>
<OPTION1></OPTION1>
<OPTION2></OPTION2>
<OPTION3></OPTION3>
<OPTION4></OPTION4>
<OPTION5></OPTION5>
<CURRENCY>GBP</CURRENCY>
<INSURANCECURRENCY>GBP</INSURANCECURRENCY>
<PAYMENTIND>S</PAYMENTIND>
<CONREF>ref01_008</CONREF>
<STATCODE>ABC</STATCODE>
</CONSIGNMENT>
</CONSIGNMENTBATCH>
使用样式表显示我的XML的任何建议。如果XML到HTML显示的任何方法都可以吗?
我使用 PHP 作为 curl 的后端脚本来获得高于 XML 的响应。
答:
0赞
Professor Abronsius
1/26/2018
#1
您可以使用 和 是 PHP 的一部分DOMDocument
XSLProcessor
<?php
$strXML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet href="https://express.tnt.com/expresswebservices-website/stylesheets/HTMLConsignmentNoteRenderer.xsl" type="text/xsl"?>
<CONSIGNMENTBATCH>
<BARCODEURL>/barbecue/barcode?type=code39&height=70&width=1&data=</BARCODEURL>
<HOST>https://express.tnt.com</HOST>
<IMAGESDIR>/expresswebservices-website/rendering/images</IMAGESDIR>
<CONSIGNMENT originCountry="AU" marketType="INTERNATIONAL">
<HEADER last="true">
<SHIPMENTDATE>29/01/2018</SHIPMENTDATE>
<SENDER>
<COMPANYNAME><![CDATA[Sender Co 01-008]]></COMPANYNAME>
<STREETADDRESS1><![CDATA[TEST DO NOT COLLECT1]]></STREETADDRESS1>
<STREETADDRESS2><![CDATA[TEST DO NOT COLLECT2]]></STREETADDRESS2>
<STREETADDRESS3><![CDATA[TEST DO NOT COLLECT3]]></STREETADDRESS3>
<CITY><![CDATA[Hoppers Crossing]]></CITY>
<POSTCODE>3029</POSTCODE>
<COUNTRY>AUSTRALIA</COUNTRY>
<CONTACTNAME><![CDATA[Mr Contact]]></CONTACTNAME>
<CONTACTDIALCODE>01827</CONTACTDIALCODE>
<CONTACTTELEPHONE>717733</CONTACTTELEPHONE>
<CONTACTEMAIL>[email protected]</CONTACTEMAIL>
<ACCOUNT>30017823</ACCOUNT>
</SENDER>
<COLLECTION>
<COMPANYNAME><![CDATA[Collection Name]]></COMPANYNAME>
<STREETADDRESS1><![CDATA[TEST DO NOT COLLECT4]]></STREETADDRESS1>
<STREETADDRESS2><![CDATA[TEST DO NOT COLLECT5]]></STREETADDRESS2>
<STREETADDRESS3><![CDATA[TEST DO NOT COLLECT6]]></STREETADDRESS3>
<CITY><![CDATA[Hoppers Crossing]]></CITY>
<POSTCODE>3029</POSTCODE>
<COUNTRY>AUSTRALIA</COUNTRY>
<CONTACTNAME><![CDATA[Mr Contact]]></CONTACTNAME>
<CONTACTDIALCODE>00000</CONTACTDIALCODE>
<CONTACTTELEPHONE>700005</CONTACTTELEPHONE>
<CONTACTEMAIL>[email protected]</CONTACTEMAIL>
</COLLECTION>
<CARRIAGEFORWARD>N</CARRIAGEFORWARD>
</HEADER>
<RECEIVER>
<COMPANYNAME><![CDATA[Receiver Name]]></COMPANYNAME>
<STREETADDRESS1><![CDATA[TEST DO NOT COLLECT7]]></STREETADDRESS1>
<STREETADDRESS2><![CDATA[TEST DO NOT COLLECT8]]></STREETADDRESS2>
<STREETADDRESS3><![CDATA[TEST DO NOT COLLECT9]]></STREETADDRESS3>
<CITY><![CDATA[Amsterdam]]></CITY>
<POSTCODE>1100 AA</POSTCODE>
<COUNTRY>NETHERLANDS</COUNTRY>
<CONTACTNAME><![CDATA[Mr Frank]]></CONTACTNAME>
<CONTACTDIALCODE>1672</CONTACTDIALCODE>
<CONTACTTELEPHONE>987432</CONTACTTELEPHONE>
<CONTACTEMAIL>[email protected]</CONTACTEMAIL>
<VAT>7668880</VAT>
</RECEIVER>
<DELIVERY>
<COMPANYNAME><![CDATA[Delivery Name]]></COMPANYNAME>
<STREETADDRESS1><![CDATA[TEST DO NOT COLLECT10]]></STREETADDRESS1>
<STREETADDRESS2><![CDATA[TEST DO NOT COLLECT11]]></STREETADDRESS2>
<STREETADDRESS3><![CDATA[TEST DO NOT COLLECT12]]></STREETADDRESS3>
<CITY><![CDATA[Amsterdam]]></CITY>
<POSTCODE>1100 AA</POSTCODE>
<COUNTRY>NETHERLANDS</COUNTRY>
<CONTACTNAME><![CDATA[Mr Frank]]></CONTACTNAME>
<CONTACTDIALCODE>1672</CONTACTDIALCODE>
<CONTACTTELEPHONE>987432</CONTACTTELEPHONE>
<CONTACTEMAIL>[email protected]</CONTACTEMAIL>
<VAT>7668880</VAT>
</DELIVERY>
<TOTALVOLUME units="m3">0.649</TOTALVOLUME>
<TOTALWEIGHT units="kg">3.60</TOTALWEIGHT>
<CUSTOMERREF><![CDATA[DISKS]]></CUSTOMERREF>
<CONSIGNMENTTYPE>N</CONSIGNMENTTYPE>
<CONNUMBER>GE161714365AU</CONNUMBER>
<SERVICE>48N Economy Express</SERVICE>
<INSURANCEVALUE>150.00</INSURANCEVALUE>
<GOODSDESC1><![CDATA[assorted office accessories]]></GOODSDESC1>
<TOTALITEMS>6</TOTALITEMS>
<GOODSVALUE>180.00</GOODSVALUE>
<DELIVERYINST><![CDATA[Delivery Instructions TEST]]></DELIVERYINST>
<OPTION1></OPTION1>
<OPTION2></OPTION2>
<OPTION3></OPTION3>
<OPTION4></OPTION4>
<OPTION5></OPTION5>
<CURRENCY>GBP</CURRENCY>
<INSURANCECURRENCY>GBP</INSURANCECURRENCY>
<PAYMENTIND>S</PAYMENTIND>
<CONREF>ref01_008</CONREF>
<STATCODE>ABC</STATCODE>
</CONSIGNMENT>
</CONSIGNMENTBATCH>';
$xml = new DOMDocument;
$xml->loadXML( $strXML );
$xsl = new DOMDocument;
$xsl->load('https://express.tnt.com/expresswebservices-website/stylesheets/HTMLConsignmentNoteRenderer.xsl');
// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules
echo $proc->transformToXML($xml);
?>
缺少可渲染的徽标可以通过生成自己的 xsl 样式表并调整路径来纠正。您可以在此处找到调整后的 xsl 文件 ~ 将副本保存到您的 Web 服务器并在处理中使用它
$xslt=__DIR__ . '/tntxsl.xsl';/* saved copy of tweaked xsl file */
$xml = new DOMDocument;
$xml->loadXML( $strXML );
$xsl = new DOMDocument;
$xsl->load( $xslt );
$proc = new XSLTProcessor;
if( !$proc->hasExsltSupport() ) {
exit('NO XSLT support');
}
$proc->importStyleSheet( $xsl );
echo $proc->transformToXML( $xml );
评论
1赞
Professor Abronsius
1/26/2018
看起来他们的 xsl 文件中有一个错误 - 徽标在路径中有一个反斜杠而不是正斜杠,并且徽标图像不会呈现。
0赞
amit nindroda
1/29/2018
有没有办法将tranformxml另存为pdf?
0赞
Professor Abronsius
1/29/2018
我会说你可以,但这是另一个问题。看一看dompdf
0赞
amit nindroda
1/30/2018
我需要为此提出另一个问题吗?
0赞
Professor Abronsius
1/30/2018
我会这么说——我不知道该怎么做,这样你才能更好地回答一个新问题。如果以上内容有助于解决原始问题,请考虑将问题标记为已解决
评论