我真的希望你能在这里提供帮助......当我使用XSLTProcessor transformToFragment对XSL样式表转换XML响应时,它似乎是在XML结构之外创建一些数据,最后: - < / p>
123456782
JohnSmith
TNTExpress
TNTHouse
ATHERSTONE
Warks
CV91TT
GB
TNTCorporateHeadOffice
Neptunusstraat41-63
Taurusavenue111
HOOFDDORP
2132LS
NL
8783802
GB
3
Express (ND)
PR
2016-11-15
INT
AIR
2
CVT
EMA
LGG
8
SP8
SP8
17
2016-11-17
63
GBP 12.34
BSH
我已经包含了XML,XSL和下面的结果,请你看一下你之前发现过这样的事情吗?
此在线工具可用于快速测试http://www.utilities-online.info/xsltransformation/
我无法看到最终生成这些数据的原因是什么,我假设它在XSL模板中的某些内容?
感谢您提供任何帮助。
编辑:看起来有人在这里有同样的问题,但没有实际的具体答案Converting XML into HTML using XSL?保
XML这里: -
<?xml version="1.0" encoding="UTF-8"?>
<labelResponse>
<consignment key="CON1">
<pieceLabelData>
<pieceNumber>1</pieceNumber>
<weightDisplay code="1.11" renderInstructions="yes">1.11kg</weightDisplay>
<pieceReference><![CDATA[piece1]]></pieceReference>
<barcode symbology="128C">1100123456782011641424002132</barcode>
<twoDBarcode symbology="pdf417"><![CDATA[123456782|123456782||1||JohnSmith|TNTExpress|ATHERSTONE|CV91TT|GB|S||TNTCorporateHeadOffice|Neptunusstraat41-63|HOOFDDORP|2132LS|NL||EX|N|PR||||0|12.34|GBP|N|||piecelinegoodsdesc|3|1.11|1.3676310000000003|N|15 Nov 2016|17:58:00]]></twoDBarcode>
</pieceLabelData>
<pieceLabelData>
<pieceNumber>2</pieceNumber>
<weightDisplay code="1.11" renderInstructions="yes">1.11kg</weightDisplay>
<pieceReference><![CDATA[piece1]]></pieceReference>
<barcode symbology="128C">1100123456782021641424002132</barcode>
<twoDBarcode symbology="pdf417"><![CDATA[123456782|123456782||2||JohnSmith|TNTExpress|ATHERSTONE|CV91TT|GB|S||TNTCorporateHeadOffice|Neptunusstraat41-63|HOOFDDORP|2132LS|NL||EX|N|PR||||0|12.34|GBP|N|||piecelinegoodsdesc|3|1.11|1.3676310000000003|N|15 Nov 2016|17:58:00]]></twoDBarcode>
</pieceLabelData>
<pieceLabelData>
<pieceNumber>3</pieceNumber>
<weightDisplay code="1.11" renderInstructions="yes">1.11kg</weightDisplay>
<pieceReference><![CDATA[piece3]]></pieceReference>
<barcode symbology="128C">1100123456782031641424002132</barcode>
<twoDBarcode symbology="pdf417"><![CDATA[123456782|123456782||3||JohnSmith|TNTExpress|ATHERSTONE|CV91TT|GB|S||TNTCorporateHeadOffice|Neptunusstraat41-63|HOOFDDORP|2132LS|NL||EX|N|PR||||0|12.34|GBP|N|||piecelinegoodsdesc|3|1.11|1.3676310000000003|N|15 Nov 2016|17:58:00]]></twoDBarcode>
</pieceLabelData>
<consignmentLabelData>
<consignmentNumber>123456782</consignmentNumber>
<sender>
<name><![CDATA[JohnSmith]]></name>
<addressLine1><![CDATA[TNTExpress]]></addressLine1>
<addressLine2><![CDATA[TNTHouse]]></addressLine2>
<town><![CDATA[ATHERSTONE]]></town>
<province><![CDATA[Warks]]></province>
<postcode><![CDATA[CV91TT]]></postcode>
<country><![CDATA[GB]]></country>
</sender>
<delivery>
<name><![CDATA[TNTCorporateHeadOffice]]></name>
<addressLine1><![CDATA[Neptunusstraat41-63]]></addressLine1>
<addressLine2><![CDATA[Taurusavenue111]]></addressLine2>
<town><![CDATA[HOOFDDORP]]></town>
<province><![CDATA[]]></province>
<postcode><![CDATA[2132LS]]></postcode>
<country><![CDATA[NL]]></country>
</delivery>
<account>
<accountNumber>8783802</accountNumber>
<accountCountry>GB</accountCountry>
</account>
<totalNumberOfPieces>3</totalNumberOfPieces>
<product id="EX">Express (ND)</product>
<option id="PR"><![CDATA[PR]]></option>
<collectionDate>2016-11-15</collectionDate>
<marketDisplay code="2" renderInstructions="yes"><![CDATA[INT]]></marketDisplay>
<transportDisplay code="1" renderInstructions="yes"><![CDATA[AIR]]></transportDisplay>
<freeCirculationDisplay code="" renderInstructions="no"/>
<sortSplitText><![CDATA[2]]></sortSplitText>
<xrayDisplay code="" renderInstructions="no"/>
<originDepot>
<depotCode>CVT</depotCode>
</originDepot>
<transitDepots>
<transitDepot>
<depotCode>EMA</depotCode>
</transitDepot>
<sortDepot>
<depotCode>LGG</depotCode>
<sortCellIndicator code="" renderInstructions="yes">8</sortCellIndicator>
<sortLocationCode>SP8</sortLocationCode>
</sortDepot>
</transitDepots>
<destinationDepot>
<depotCode>SP8</depotCode>
<dueDayOfMonth>17</dueDayOfMonth>
<dueDate>2016-11-17</dueDate>
</destinationDepot>
<microzone code="" renderInstructions="no"/>
<clusterCode>63</clusterCode>
<legalComments/>
<cashAmount code="12.34" renderInstructions="yes">GBP 12.34</cashAmount>
<specialInstructions/>
<bulkShipment code="Y" renderInstructions="yes">BSH</bulkShipment>
</consignmentLabelData>
</consignment>
</labelResponse>
XSL在这里: -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="RestOfWorldHtml" match="pieceLabelData">
<div id="box">
<!--Logo-->
<div id="logo">
<img src='https://express.tnt.com/expresswebservices-website/rendering/images/logo_orig.jpg' alt='logo' id="tntLogo" />
</div>
<!--Market & Transport Type-->
<div id="marketAndTransportType">
<xsl:value-of select="../consignmentLabelData/marketDisplay"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="../consignmentLabelData/transportDisplay"/>
</div>
<!--Hazardous-->
<div id="hazardous">.
<xsl:for-each select="../consignmentLabelData/option">
<xsl:if test="@id='HZ'">
<xsl:text>HAZARDOUS</xsl:text>
</xsl:if>
</xsl:for-each>
</div>
<!--X-RAY-->
<xsl:if test="string-length(../consignmentLabelData/xrayDisplay)>0">
<div id="xray">
<xsl:value-of select="../consignmentLabelData/xrayDisplay"/>
</div>
</xsl:if>
<!--Free Circulation Display-->
<xsl:choose>
<xsl:when test="string-length(../consignmentLabelData/freeCirculationDisplay)>0">
<div id="freeCirculationIndicator" style="background-color: #000000;color: #FFFFFF;">
<xsl:value-of select="../consignmentLabelData/freeCirculationDisplay"/>
</div>
</xsl:when>
<xsl:otherwise>
<div id="freeCirculationIndicator" style="background-color: #000000;color: #000000;">
<xsl:text> </xsl:text>
</div>
</xsl:otherwise>
</xsl:choose>
<!--Sort Split Indicator-->
<xsl:choose>
<xsl:when test="string-length(../consignmentLabelData/sortSplitText)>0">
<div id="sortSplitIndicator">
<xsl:value-of select="../consignmentLabelData/sortSplitText" />
</div>
</xsl:when>
<xsl:otherwise>
<div id="sortSplitIndicator">
<xsl:text> </xsl:text>
</div>
</xsl:otherwise>
</xsl:choose>
<!--Consignment Number-->
<div id="conNumber">
<div id="conNumberHeader">Con No.</div>
<div id="conNumberDetail"><xsl:value-of select="../consignmentLabelData/consignmentNumber"/></div>
</div>
<!--Service-->
<div id="service">
<div id="serviceHeader">Service</div>
<xsl:choose>
<xsl:when test="string-length(../consignmentLabelData/product)>15">
<span id="serviceDetail" style="font-size: 17px;">
<xsl:value-of select="../consignmentLabelData/product" />
</span>
</xsl:when>
<xsl:otherwise>
<span id="serviceDetail" style="font-size: 20px;">
<xsl:value-of select="../consignmentLabelData/product" />
</span>
</xsl:otherwise>
</xsl:choose>
</div>
<!--Pieces-->
<div id="piece">
<div id="pieceHeader">
Piece
</div>
<div id="pieceDetail"><xsl:value-of select="pieceNumber"/> of <xsl:value-of select="../consignmentLabelData/totalNumberOfPieces"/></div>
</div>
<!--Weight-->
<div id="weight">
<div id="weightHeader">
Weight
</div>
<xsl:choose>
<xsl:when test="weightDisplay/@renderInstructions='highlighted'">
<span id="weightDetailHighlighted">
<xsl:value-of select="weightDisplay" />
</span>
</xsl:when>
<xsl:otherwise>
<span id="weightDetail">
<xsl:value-of select="weightDisplay" />
</span>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
</div>
<!--Options-->
<div id="option">
<div id="optionHeader">Option</div>
<xsl:variable name="numberOptions" select="count(../consignmentLabelData/option)" />
<xsl:choose>
<!--If there are multiple options then display option id only-->
<xsl:when test="$numberOptions >1">
<xsl:for-each select="../consignmentLabelData/option">
<div id="optionDetail">
<xsl:value-of select="@id" />
<xsl:text> </xsl:text>
</div>
</xsl:for-each>
</xsl:when>
<!--If there is only one option then display the option description-->
<xsl:otherwise>
<xsl:choose>
<xsl:when test="string-length(../consignmentLabelData/option)>0">
<div id="optionDetail">
<xsl:value-of select="../consignmentLabelData/option" />
</div>
</xsl:when>
<xsl:otherwise>
<div id="optionDetail">
<xsl:text> </xsl:text>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</div>
<!--Customer Reference & Account Number-->
<div id="customerReference">
<div id="customerReferenceHeader">Customer Reference</div>
<div id="customerReferenceDetail"><xsl:value-of select="pieceReference" disable-output-escaping="yes" /></div>
</div>
<div id="accountNumber">
<span id="accountNumberHeader">S/R Account No</span>
<span id="accountNumberDetail"><xsl:value-of select="../consignmentLabelData/account/accountNumber" /></span>
</div>
<!--Origin Depot & Pickup Date-->
<div id="originDepot">
<span id="originDepotHeader">Origin</span>
<span id="originDepotDetail"><xsl:value-of select="../consignmentLabelData/originDepot/depotCode" /></span>
</div>
<div id="pickupDate">
<div id="pickupDateHeader">Pickup Date</div>
<div id="pickupDateDetail">
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTime" select="../consignmentLabelData/collectionDate"/>
</xsl:call-template>
</div>
</div>
<!--Origin Address & Delivery Address-->
<div id="senderAddress">
<div id="senderAddressHeader">Sender Address</div>
<div id="senderAddressDetail">
<xsl:value-of select="../consignmentLabelData/sender/name" disable-output-escaping="yes"/><br />
<xsl:value-of select="../consignmentLabelData/sender/addressLine1" disable-output-escaping="yes"/><br />
<xsl:value-of select="../consignmentLabelData/sender/addressLine2" disable-output-escaping="yes"/><br />
<xsl:value-of select="../consignmentLabelData/sender/town" disable-output-escaping="yes"/><xsl:text> </xsl:text>
<xsl:value-of select="../consignmentLabelData/sender/postcode"/><br />
<xsl:value-of select="../consignmentLabelData/sender/country"/>
</div>
</div>
<div id="deliveryAddress">
<div id="deliveryAddressHeader">Delivery Address</div>
<div id="deliveryAddressDetail">
<xsl:value-of select="../consignmentLabelData/delivery/name" disable-output-escaping="yes"/><br />
<xsl:value-of select="../consignmentLabelData/delivery/addressLine1" disable-output-escaping="yes"/><br />
<xsl:value-of select="../consignmentLabelData/delivery/addressLine2" disable-output-escaping="yes"/><br />
<xsl:value-of select="../consignmentLabelData/delivery/town" disable-output-escaping="yes"/><xsl:text> </xsl:text>
<xsl:value-of select="../consignmentLabelData/delivery/postcode"/><br />
<xsl:value-of select="../consignmentLabelData/delivery/country"/>
</div>
</div>
<!-- Route Details-->
<div id="routing">
<span id="routingHeader">Routing</span>
<div id="routingDetail">
<!-- Check if route includes any transit depots-->
<xsl:if test="count(../consignmentLabelData/transitDepots/*)=0">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:for-each select="../consignmentLabelData/transitDepots/*">
<xsl:if test="name(self::node()[position()])='transitDepot'">
<xsl:value-of select="depotCode" />
<br />
</xsl:if>
<xsl:if test="name(self::node()[position()])='actionDepot'">
<xsl:value-of select="depotCode" />
<xsl:text>-</xsl:text>
<xsl:value-of select="actionDayOfWeek" />
<br />
</xsl:if>
<xsl:if test="name(self::node()[position()])='sortDepot'">
<xsl:value-of select="depotCode" />
<xsl:text>-</xsl:text>
<xsl:value-of select="sortCellIndicator" />
<br />
</xsl:if>
</xsl:for-each>
</div>
</div>
<!--Sort Details-->
<div id="sort">
<span id="sortHeader">Sort</span>
<span id="sortDetail">
<xsl:value-of select="../consignmentLabelData/transitDepots/sortDepot/depotCode" />
<xsl:text> </xsl:text>
</span>
</div>
<!--Postcode/Cluster code-->
<div id="postcodeHeader">Postcode /
<br />
Cluster Code
</div>
<div id="postcode">
<xsl:choose>
<!--If the length of the Cluster code is greater than 3 then the post code is being displayed
instead, so different rendering applies-->
<xsl:when test="string-length(../consignmentLabelData/clusterCode)>3">
<span id="postcodeDetail"><xsl:value-of select="../consignmentLabelData/delivery/postcode"/></span>
</xsl:when>
<xsl:otherwise>
<span id="clustercodeDetail"><xsl:value-of select="../consignmentLabelData/clusterCode"/></span>
</xsl:otherwise>
</xsl:choose>
</div>
<!--Destination Depot-->
<div id="destinationDepotHeader">
Dest
<br />
Depot
</div>
<div id="destinationDepotDetail">
<xsl:choose>
<xsl:when test="../consignmentLabelData/destinationDepot/dueDayOfWeek/@renderInstructions='highlighted'">
<xsl:value-of select="../consignmentLabelData/destinationDepot/depotCode"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="../consignmentLabelData/destinationDepot/dueDayOfMonth"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="../consignmentLabelData/destinationDepot/depotCode"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="../consignmentLabelData/destinationDepot/dueDayOfMonth"/>
</xsl:otherwise>
</xsl:choose>
</div>
<!--Barcode-->
<xsl:variable name="barcode_url" select='"https://express.tnt.com/barbecue/barcode?type=Code128C&height=140&width=2&data="' />
<div id="barcode" name="barcode">
<img>
<xsl:attribute name="src">
<xsl:value-of select="concat($barcode_url,barcode)" />
</xsl:attribute>
</img>
</div>
<div id="barcodeLabel">
<xsl:value-of select="barcode" />
</div>
</div>
<br style="page-break-before:always"/>
</xsl:template>
<xsl:template name="FormatDate">
<!-- expected date format 2008 06 16 -->
<xsl:param name="DateTime" />
<!-- new date format 20 June 2007 -->
<xsl:variable name="year">
<xsl:value-of select="substring-before($DateTime,'-')" />
</xsl:variable>
<xsl:variable name="mo-temp">
<xsl:value-of select="substring-after($DateTime,'-')" />
</xsl:variable>
<xsl:variable name="mo">
<xsl:value-of select="substring-before($mo-temp,'-')" />
</xsl:variable>
<xsl:variable name="day">
<xsl:value-of select="substring-after($mo-temp,'-')" />
</xsl:variable>
<xsl:value-of select="$day" />
<xsl:text> </xsl:text>
<xsl:choose>
<xsl:when test="$mo = '1' or $mo = '01'">Jan</xsl:when>
<xsl:when test="$mo = '2' or $mo = '02'">Feb</xsl:when>
<xsl:when test="$mo = '3' or $mo = '03'">Mar</xsl:when>
<xsl:when test="$mo = '4' or $mo = '04'">Apr</xsl:when>
<xsl:when test="$mo = '5' or $mo = '05'">May</xsl:when>
<xsl:when test="$mo = '6' or $mo = '06'">Jun</xsl:when>
<xsl:when test="$mo = '7' or $mo = '07'">Jul</xsl:when>
<xsl:when test="$mo = '8' or $mo = '08'">Aug</xsl:when>
<xsl:when test="$mo = '9' or $mo = '09'">Sep</xsl:when>
<xsl:when test="$mo = '10'">Oct</xsl:when>
<xsl:when test="$mo = '11'">Nov</xsl:when>
<xsl:when test="$mo = '12'">Dec</xsl:when>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:value-of select="$year" />
</xsl:template>
</xsl:stylesheet>
转换后的结果: -
<?xml version="1.0" encoding="UTF-8"?>
<div id="box"><div id="logo"><img id="tntLogo" alt="logo" src="https://express.tnt.com/expresswebservices-website/rendering/images/logo_orig.jpg"/></div><div id="marketAndTransportType">INT/AIR</div><div id="hazardous">.
</div><div style="background-color: #000000;color: #000000;" id="freeCirculationIndicator"> </div><div id="sortSplitIndicator">2</div><div id="conNumber"><div id="conNumberHeader">Con No.</div><div id="conNumberDetail">123456782</div></div><div id="service"><div id="serviceHeader">Service</div><span style="font-size: 20px;" id="serviceDetail">Express (ND)</span></div><div id="piece"><div id="pieceHeader">
Piece
</div><div id="pieceDetail">1 of 3</div></div><div id="weight"><div id="weightHeader">
Weight
</div><span id="weightDetail">1.11kg</span> </div><div id="option"><div id="optionHeader">Option</div><div id="optionDetail">PR</div></div><div id="customerReference"><div id="customerReferenceHeader">Customer Reference</div><div id="customerReferenceDetail">piece1</div></div><div id="accountNumber"><span id="accountNumberHeader">S/R Account No</span><span id="accountNumberDetail">8783802</span></div><div id="originDepot"><span id="originDepotHeader">Origin</span><span id="originDepotDetail">CVT</span></div><div id="pickupDate"><div id="pickupDateHeader">Pickup Date</div><div id="pickupDateDetail">15 Nov 2016</div></div><div id="senderAddress"><div id="senderAddressHeader">Sender Address</div><div id="senderAddressDetail">JohnSmith<br/>TNTExpress<br/>TNTHouse<br/>ATHERSTONE CV91TT<br/>GB</div></div><div id="deliveryAddress"><div id="deliveryAddressHeader">Delivery Address</div><div id="deliveryAddressDetail">TNTCorporateHeadOffice<br/>Neptunusstraat41-63<br/>Taurusavenue111<br/>HOOFDDORP 2132LS<br/>NL</div></div><div id="routing"><span id="routingHeader">Routing</span><div id="routingDetail">EMA<br/>LGG-8<br/></div></div><div id="sort"><span id="sortHeader">Sort</span><span id="sortDetail">LGG </span></div><div id="postcodeHeader">Postcode /
<br/>
Cluster Code
</div><div id="postcode"><span id="clustercodeDetail">63</span></div><div id="destinationDepotHeader">
Dest
<br/>
Depot
</div><div id="destinationDepotDetail">SP8-17</div><div name="barcode" id="barcode"><img src="https://express.tnt.com/barbecue/barcode?type=Code128C&height=140&width=2&data=1100123456782011641424002132"/></div><div id="barcodeLabel">1100123456782011641424002132</div></div><br style="page-break-before:always"/>
<div id="box"><div id="logo"><img id="tntLogo" alt="logo" src="https://express.tnt.com/expresswebservices-website/rendering/images/logo_orig.jpg"/></div><div id="marketAndTransportType">INT/AIR</div><div id="hazardous">.
</div><div style="background-color: #000000;color: #000000;" id="freeCirculationIndicator"> </div><div id="sortSplitIndicator">2</div><div id="conNumber"><div id="conNumberHeader">Con No.</div><div id="conNumberDetail">123456782</div></div><div id="service"><div id="serviceHeader">Service</div><span style="font-size: 20px;" id="serviceDetail">Express (ND)</span></div><div id="piece"><div id="pieceHeader">
Piece
</div><div id="pieceDetail">2 of 3</div></div><div id="weight"><div id="weightHeader">
Weight
</div><span id="weightDetail">1.11kg</span> </div><div id="option"><div id="optionHeader">Option</div><div id="optionDetail">PR</div></div><div id="customerReference"><div id="customerReferenceHeader">Customer Reference</div><div id="customerReferenceDetail">piece1</div></div><div id="accountNumber"><span id="accountNumberHeader">S/R Account No</span><span id="accountNumberDetail">8783802</span></div><div id="originDepot"><span id="originDepotHeader">Origin</span><span id="originDepotDetail">CVT</span></div><div id="pickupDate"><div id="pickupDateHeader">Pickup Date</div><div id="pickupDateDetail">15 Nov 2016</div></div><div id="senderAddress"><div id="senderAddressHeader">Sender Address</div><div id="senderAddressDetail">JohnSmith<br/>TNTExpress<br/>TNTHouse<br/>ATHERSTONE CV91TT<br/>GB</div></div><div id="deliveryAddress"><div id="deliveryAddressHeader">Delivery Address</div><div id="deliveryAddressDetail">TNTCorporateHeadOffice<br/>Neptunusstraat41-63<br/>Taurusavenue111<br/>HOOFDDORP 2132LS<br/>NL</div></div><div id="routing"><span id="routingHeader">Routing</span><div id="routingDetail">EMA<br/>LGG-8<br/></div></div><div id="sort"><span id="sortHeader">Sort</span><span id="sortDetail">LGG </span></div><div id="postcodeHeader">Postcode /
<br/>
Cluster Code
</div><div id="postcode"><span id="clustercodeDetail">63</span></div><div id="destinationDepotHeader">
Dest
<br/>
Depot
</div><div id="destinationDepotDetail">SP8-17</div><div name="barcode" id="barcode"><img src="https://express.tnt.com/barbecue/barcode?type=Code128C&height=140&width=2&data=1100123456782021641424002132"/></div><div id="barcodeLabel">1100123456782021641424002132</div></div><br style="page-break-before:always"/>
<div id="box"><div id="logo"><img id="tntLogo" alt="logo" src="https://express.tnt.com/expresswebservices-website/rendering/images/logo_orig.jpg"/></div><div id="marketAndTransportType">INT/AIR</div><div id="hazardous">.
</div><div style="background-color: #000000;color: #000000;" id="freeCirculationIndicator"> </div><div id="sortSplitIndicator">2</div><div id="conNumber"><div id="conNumberHeader">Con No.</div><div id="conNumberDetail">123456782</div></div><div id="service"><div id="serviceHeader">Service</div><span style="font-size: 20px;" id="serviceDetail">Express (ND)</span></div><div id="piece"><div id="pieceHeader">
Piece
</div><div id="pieceDetail">3 of 3</div></div><div id="weight"><div id="weightHeader">
Weight
</div><span id="weightDetail">1.11kg</span> </div><div id="option"><div id="optionHeader">Option</div><div id="optionDetail">PR</div></div><div id="customerReference"><div id="customerReferenceHeader">Customer Reference</div><div id="customerReferenceDetail">piece3</div></div><div id="accountNumber"><span id="accountNumberHeader">S/R Account No</span><span id="accountNumberDetail">8783802</span></div><div id="originDepot"><span id="originDepotHeader">Origin</span><span id="originDepotDetail">CVT</span></div><div id="pickupDate"><div id="pickupDateHeader">Pickup Date</div><div id="pickupDateDetail">15 Nov 2016</div></div><div id="senderAddress"><div id="senderAddressHeader">Sender Address</div><div id="senderAddressDetail">JohnSmith<br/>TNTExpress<br/>TNTHouse<br/>ATHERSTONE CV91TT<br/>GB</div></div><div id="deliveryAddress"><div id="deliveryAddressHeader">Delivery Address</div><div id="deliveryAddressDetail">TNTCorporateHeadOffice<br/>Neptunusstraat41-63<br/>Taurusavenue111<br/>HOOFDDORP 2132LS<br/>NL</div></div><div id="routing"><span id="routingHeader">Routing</span><div id="routingDetail">EMA<br/>LGG-8<br/></div></div><div id="sort"><span id="sortHeader">Sort</span><span id="sortDetail">LGG </span></div><div id="postcodeHeader">Postcode /
<br/>
Cluster Code
</div><div id="postcode"><span id="clustercodeDetail">63</span></div><div id="destinationDepotHeader">
Dest
<br/>
Depot
</div><div id="destinationDepotDetail">SP8-17</div><div name="barcode" id="barcode"><img src="https://express.tnt.com/barbecue/barcode?type=Code128C&height=140&width=2&data=1100123456782031641424002132"/></div><div id="barcodeLabel">1100123456782031641424002132</div></div><br style="page-break-before:always"/>
123456782
JohnSmith
TNTExpress
TNTHouse
ATHERSTONE
Warks
CV91TT
GB
TNTCorporateHeadOffice
Neptunusstraat41-63
Taurusavenue111
HOOFDDORP
2132LS
NL
8783802
GB
3
Express (ND)
PR
2016-11-15
INT
AIR
2
CVT
EMA
LGG
8
SP8
SP8
17
2016-11-17
63
GBP 12.34
BSH
答案 0 :(得分:1)
您似乎编写了一个匹配模板,因此built-in templates处理其他元素,将任何文本节点子节点复制到结果中。添加<xsl:template match="text()"/>
以防止一般情况下或在入口点使用<xsl:template match="/"><xsl:apply-templates select="//pieceLabelData"/></xsl:template>
。我希望已经足够了,你已经发布了我没有检查过所有代码的长片段,所以我认为诊断和解释都很好,希望建议的修复也足够了。
所以你需要
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template name="RestOfWorldHtml" match="pieceLabelData">
<div id="box">
<!--Logo-->
<div id="logo">
<img src='https://express.tnt.com/expresswebservices-website/rendering/images/logo_orig.jpg' alt='logo' id="tntLogo" />
</div>
<!--Market & Transport Type-->
<div id="marketAndTransportType">
<xsl:value-of select="../consignmentLabelData/marketDisplay"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="../consignmentLabelData/transportDisplay"/>
</div>
<!--Hazardous-->
<div id="hazardous">.
<xsl:for-each select="../consignmentLabelData/option">
<xsl:if test="@id='HZ'">
<xsl:text>HAZARDOUS</xsl:text>
</xsl:if>
</xsl:for-each>
</div>
<!--X-RAY-->
<xsl:if test="string-length(../consignmentLabelData/xrayDisplay)>0">
<div id="xray">
<xsl:value-of select="../consignmentLabelData/xrayDisplay"/>
</div>
</xsl:if>
<!--Free Circulation Display-->
<xsl:choose>
<xsl:when test="string-length(../consignmentLabelData/freeCirculationDisplay)>0">
<div id="freeCirculationIndicator" style="background-color: #000000;color: #FFFFFF;">
<xsl:value-of select="../consignmentLabelData/freeCirculationDisplay"/>
</div>
</xsl:when>
<xsl:otherwise>
<div id="freeCirculationIndicator" style="background-color: #000000;color: #000000;">
<xsl:text> </xsl:text>
</div>
</xsl:otherwise>
</xsl:choose>
<!--Sort Split Indicator-->
<xsl:choose>
<xsl:when test="string-length(../consignmentLabelData/sortSplitText)>0">
<div id="sortSplitIndicator">
<xsl:value-of select="../consignmentLabelData/sortSplitText" />
</div>
</xsl:when>
<xsl:otherwise>
<div id="sortSplitIndicator">
<xsl:text> </xsl:text>
</div>
</xsl:otherwise>
</xsl:choose>
<!--Consignment Number-->
<div id="conNumber">
<div id="conNumberHeader">Con No.</div>
<div id="conNumberDetail"><xsl:value-of select="../consignmentLabelData/consignmentNumber"/></div>
</div>
<!--Service-->
<div id="service">
<div id="serviceHeader">Service</div>
<xsl:choose>
<xsl:when test="string-length(../consignmentLabelData/product)>15">
<span id="serviceDetail" style="font-size: 17px;">
<xsl:value-of select="../consignmentLabelData/product" />
</span>
</xsl:when>
<xsl:otherwise>
<span id="serviceDetail" style="font-size: 20px;">
<xsl:value-of select="../consignmentLabelData/product" />
</span>
</xsl:otherwise>
</xsl:choose>
</div>
<!--Pieces-->
<div id="piece">
<div id="pieceHeader">
Piece
</div>
<div id="pieceDetail"><xsl:value-of select="pieceNumber"/> of <xsl:value-of select="../consignmentLabelData/totalNumberOfPieces"/></div>
</div>
<!--Weight-->
<div id="weight">
<div id="weightHeader">
Weight
</div>
<xsl:choose>
<xsl:when test="weightDisplay/@renderInstructions='highlighted'">
<span id="weightDetailHighlighted">
<xsl:value-of select="weightDisplay" />
</span>
</xsl:when>
<xsl:otherwise>
<span id="weightDetail">
<xsl:value-of select="weightDisplay" />
</span>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
</div>
<!--Options-->
<div id="option">
<div id="optionHeader">Option</div>
<xsl:variable name="numberOptions" select="count(../consignmentLabelData/option)" />
<xsl:choose>
<!--If there are multiple options then display option id only-->
<xsl:when test="$numberOptions >1">
<xsl:for-each select="../consignmentLabelData/option">
<div id="optionDetail">
<xsl:value-of select="@id" />
<xsl:text> </xsl:text>
</div>
</xsl:for-each>
</xsl:when>
<!--If there is only one option then display the option description-->
<xsl:otherwise>
<xsl:choose>
<xsl:when test="string-length(../consignmentLabelData/option)>0">
<div id="optionDetail">
<xsl:value-of select="../consignmentLabelData/option" />
</div>
</xsl:when>
<xsl:otherwise>
<div id="optionDetail">
<xsl:text> </xsl:text>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</div>
<!--Customer Reference & Account Number-->
<div id="customerReference">
<div id="customerReferenceHeader">Customer Reference</div>
<div id="customerReferenceDetail"><xsl:value-of select="pieceReference" disable-output-escaping="yes" /></div>
</div>
<div id="accountNumber">
<span id="accountNumberHeader">S/R Account No</span>
<span id="accountNumberDetail"><xsl:value-of select="../consignmentLabelData/account/accountNumber" /></span>
</div>
<!--Origin Depot & Pickup Date-->
<div id="originDepot">
<span id="originDepotHeader">Origin</span>
<span id="originDepotDetail"><xsl:value-of select="../consignmentLabelData/originDepot/depotCode" /></span>
</div>
<div id="pickupDate">
<div id="pickupDateHeader">Pickup Date</div>
<div id="pickupDateDetail">
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTime" select="../consignmentLabelData/collectionDate"/>
</xsl:call-template>
</div>
</div>
<!--Origin Address & Delivery Address-->
<div id="senderAddress">
<div id="senderAddressHeader">Sender Address</div>
<div id="senderAddressDetail">
<xsl:value-of select="../consignmentLabelData/sender/name" disable-output-escaping="yes"/><br />
<xsl:value-of select="../consignmentLabelData/sender/addressLine1" disable-output-escaping="yes"/><br />
<xsl:value-of select="../consignmentLabelData/sender/addressLine2" disable-output-escaping="yes"/><br />
<xsl:value-of select="../consignmentLabelData/sender/town" disable-output-escaping="yes"/><xsl:text> </xsl:text>
<xsl:value-of select="../consignmentLabelData/sender/postcode"/><br />
<xsl:value-of select="../consignmentLabelData/sender/country"/>
</div>
</div>
<div id="deliveryAddress">
<div id="deliveryAddressHeader">Delivery Address</div>
<div id="deliveryAddressDetail">
<xsl:value-of select="../consignmentLabelData/delivery/name" disable-output-escaping="yes"/><br />
<xsl:value-of select="../consignmentLabelData/delivery/addressLine1" disable-output-escaping="yes"/><br />
<xsl:value-of select="../consignmentLabelData/delivery/addressLine2" disable-output-escaping="yes"/><br />
<xsl:value-of select="../consignmentLabelData/delivery/town" disable-output-escaping="yes"/><xsl:text> </xsl:text>
<xsl:value-of select="../consignmentLabelData/delivery/postcode"/><br />
<xsl:value-of select="../consignmentLabelData/delivery/country"/>
</div>
</div>
<!-- Route Details-->
<div id="routing">
<span id="routingHeader">Routing</span>
<div id="routingDetail">
<!-- Check if route includes any transit depots-->
<xsl:if test="count(../consignmentLabelData/transitDepots/*)=0">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:for-each select="../consignmentLabelData/transitDepots/*">
<xsl:if test="name(self::node()[position()])='transitDepot'">
<xsl:value-of select="depotCode" />
<br />
</xsl:if>
<xsl:if test="name(self::node()[position()])='actionDepot'">
<xsl:value-of select="depotCode" />
<xsl:text>-</xsl:text>
<xsl:value-of select="actionDayOfWeek" />
<br />
</xsl:if>
<xsl:if test="name(self::node()[position()])='sortDepot'">
<xsl:value-of select="depotCode" />
<xsl:text>-</xsl:text>
<xsl:value-of select="sortCellIndicator" />
<br />
</xsl:if>
</xsl:for-each>
</div>
</div>
<!--Sort Details-->
<div id="sort">
<span id="sortHeader">Sort</span>
<span id="sortDetail">
<xsl:value-of select="../consignmentLabelData/transitDepots/sortDepot/depotCode" />
<xsl:text> </xsl:text>
</span>
</div>
<!--Postcode/Cluster code-->
<div id="postcodeHeader">Postcode /
<br />
Cluster Code
</div>
<div id="postcode">
<xsl:choose>
<!--If the length of the Cluster code is greater than 3 then the post code is being displayed
instead, so different rendering applies-->
<xsl:when test="string-length(../consignmentLabelData/clusterCode)>3">
<span id="postcodeDetail"><xsl:value-of select="../consignmentLabelData/delivery/postcode"/></span>
</xsl:when>
<xsl:otherwise>
<span id="clustercodeDetail"><xsl:value-of select="../consignmentLabelData/clusterCode"/></span>
</xsl:otherwise>
</xsl:choose>
</div>
<!--Destination Depot-->
<div id="destinationDepotHeader">
Dest
<br />
Depot
</div>
<div id="destinationDepotDetail">
<xsl:choose>
<xsl:when test="../consignmentLabelData/destinationDepot/dueDayOfWeek/@renderInstructions='highlighted'">
<xsl:value-of select="../consignmentLabelData/destinationDepot/depotCode"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="../consignmentLabelData/destinationDepot/dueDayOfMonth"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="../consignmentLabelData/destinationDepot/depotCode"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="../consignmentLabelData/destinationDepot/dueDayOfMonth"/>
</xsl:otherwise>
</xsl:choose>
</div>
<!--Barcode-->
<xsl:variable name="barcode_url" select='"https://express.tnt.com/barbecue/barcode?type=Code128C&height=140&width=2&data="' />
<div id="barcode" name="barcode">
<img>
<xsl:attribute name="src">
<xsl:value-of select="concat($barcode_url,barcode)" />
</xsl:attribute>
</img>
</div>
<div id="barcodeLabel">
<xsl:value-of select="barcode" />
</div>
</div>
<br style="page-break-before:always"/>
</xsl:template>
<xsl:template name="FormatDate">
<!-- expected date format 2008 06 16 -->
<xsl:param name="DateTime" />
<!-- new date format 20 June 2007 -->
<xsl:variable name="year">
<xsl:value-of select="substring-before($DateTime,'-')" />
</xsl:variable>
<xsl:variable name="mo-temp">
<xsl:value-of select="substring-after($DateTime,'-')" />
</xsl:variable>
<xsl:variable name="mo">
<xsl:value-of select="substring-before($mo-temp,'-')" />
</xsl:variable>
<xsl:variable name="day">
<xsl:value-of select="substring-after($mo-temp,'-')" />
</xsl:variable>
<xsl:value-of select="$day" />
<xsl:text> </xsl:text>
<xsl:choose>
<xsl:when test="$mo = '1' or $mo = '01'">Jan</xsl:when>
<xsl:when test="$mo = '2' or $mo = '02'">Feb</xsl:when>
<xsl:when test="$mo = '3' or $mo = '03'">Mar</xsl:when>
<xsl:when test="$mo = '4' or $mo = '04'">Apr</xsl:when>
<xsl:when test="$mo = '5' or $mo = '05'">May</xsl:when>
<xsl:when test="$mo = '6' or $mo = '06'">Jun</xsl:when>
<xsl:when test="$mo = '7' or $mo = '07'">Jul</xsl:when>
<xsl:when test="$mo = '8' or $mo = '08'">Aug</xsl:when>
<xsl:when test="$mo = '9' or $mo = '09'">Sep</xsl:when>
<xsl:when test="$mo = '10'">Oct</xsl:when>
<xsl:when test="$mo = '11'">Nov</xsl:when>
<xsl:when test="$mo = '12'">Dec</xsl:when>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:value-of select="$year" />
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>