以下代码用于将XML文档转换为HTML文档:
XslTransform vXslTransform = new XslTransform();
XmlReader vReader = new XmlTextReader(new StringReader(this.Xslt));
vXslTransform.Load(vReader,null as XmlResolver, null as System.Security.Policy.Evidence);
StringWriter vStringWriter = new StringWriter();
vXslTransform.Transform(this.XmlDocument, null, vStringWriter, null);
此代码已经使用多年了。然后我来了,我想要做的就是添加一个URL到混合。您可以在下面的XML中看到新的URL(CoreReturnLabel元素):
<CoreReturnEmail>
<CoreReturnLabel>https://www.example.com/SomePage.pdf?token=eaf5383bddb9382f5&createdby=f01ddedb0aedd87fe44b9b9b741</CoreReturnLabel>
<CoreReturn>
<CoreReturnID>12345</CoreReturnID>
<HashedCoreReturnID>sdjhgfuidhcbjhsdgifljsdjgfuio</HashedCoreReturnID>
<VendorShipItem>
<Quantity>1</Quantity>
<VendorShipment>
<ActualShipDate>5/31/2016</ActualShipDate>
</VendorShipment>
<VendorOrderItem>
<OrderItem>
<CoreCharge>40.00</CoreCharge>
<PartsearchSKU>
<Item>
<Name>Some name</Name>
<Description>That thing</Description>
<DisplayNumber>734-3647-4748</DisplayNumber>
<Brand>
<PreferredName>Brand</PreferredName>
</Brand>
<AdditionalShippingType>
<Description>No Additional Shipping Charges</Description>
</AdditionalShippingType>
</Item>
</PartsearchSKU>
<OrderItemState>
<Name>Sourced</Name>
</OrderItemState>
<Quantity>5</Quantity>
<UnitSellingPrice>179.00</UnitSellingPrice>
<LineDiscountTotal>0.00</LineDiscountTotal>
<LineTotal>895.00</LineTotal>
<UnitAddShippingFee>0.00</UnitAddShippingFee>
<UnitAddShippingFeeLineTotal>0.00</UnitAddShippingFeeLineTotal>
<IsOversizedShipping>False</IsOversizedShipping>
</OrderItem>
<VendorOrder>
<OrderNumber>12345678</OrderNumber>
<Order>
<ReturnsPortalUrl></ReturnsPortalUrl>
<ShipToFirstName>CHICAGO</ShipToFirstName>
<ShipToLastName>CHICAGO</ShipToLastName>
<ShipToAddressLine1>1600 Parkway PKWY</ShipToAddressLine1>
<ShipToAddressLine2></ShipToAddressLine2>
<ShipToCompany>CHICAGO</ShipToCompany>
<ShipToCity>The one</ShipToCity>
<ShipToPostalCode>12345</ShipToPostalCode>
<ShipToProvince>
<Code>AL</Code>
</ShipToProvince>
<ShipToCountry>
<Name>United States</Name>
</ShipToCountry>
<BillToFirstName>Yep</BillToFirstName>
<BillToLastName>Me</BillToLastName>
<BillToAddressLine1>That place</BillToAddressLine1>
<BillToAddressLine2></BillToAddressLine2>
<BillToCompany>CHICAGO</BillToCompany>
<BillToCity></BillToCity>
<BillToPostalCode>12345</BillToPostalCode>
<BillToProvince>
<Code>AL</Code>
</BillToProvince>
<BillToCountry>
<Name>United States</Name>
</BillToCountry>
<OrderChannel>
<Name>OC1</Name>
<DisplayName>OC1</DisplayName>
<Code></Code>
<AuthorizationType>
<Name></Name>
<Code></Code>
<Description></Description>
</AuthorizationType>
<PrimaryURL></PrimaryURL>
<WebSiteOrderChannelCode></WebSiteOrderChannelCode>
<CustomerServicePhone></CustomerServicePhone>
<PhoneDescription></PhoneDescription>
<EmailDomain></EmailDomain>
<ClientCode></ClientCode>
<PCI></PCI>
<ClientProgram>
<BrandedName></BrandedName>
<DaysAllowedForCoreReturn></DaysAllowedForCoreReturn>
</ClientProgram>
</OrderChannel>
</Order>
<Vendor>
<Name></Name>
</Vendor>
</VendorOrder>
</VendorOrderItem>
</VendorShipItem>
</CoreReturn>
XSLT如下:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="no" method="html" />
<xsl:template match="/">
<xsl:variable name="isFred">
<xsl:choose>
<xsl:when test="contains(CoreReturnEmail/CoreReturn/VendorShipItem/VendorOrderItem/VendorOrder/Order/OrderChannel/WebSiteOrderChannelCode,'GSSC')"> yes </xsl:when>
</xsl:choose>
</xsl:variable>
<html>
<head>
<title>Your Core Has Been Received</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body style="font-family : Arial, sans-serif;">
<table width="700" cellspacing="0" cellpadding="0">
<tr>
<td>
<xsl:choose>
<xsl:when test="string($isFred)">
<img src="http://content.gif" border="0" />
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="string-length(CoreReturnEmail/CoreReturn/VendorShipItem/VendorOrderItem/VendorOrder/Order/OrderChannel/PrimaryURL) > 0">
<a href="http://{CoreReturnEmail/CoreReturn/VendorShipItem/VendorOrderItem/VendorOrder/Order/OrderChannel/PrimaryURL}">
<img src="http://content.gif" border="0" />
</a>
</xsl:when>
<xsl:otherwise>
<img src="http://content.gif" border="0" />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
<br />
<br />
<span style="font-family : Tahoma, Arial, sans-serif; font-size:21pt; font-weight : bold; color : #1f415c;">Core Return:</span>
<span style="font-family : Tahoma, Arial, sans-serif; font-size:17pt; font-weight : bold; color : #1f415c;"> Order #</span>
<span style="font-family : Tahoma, Arial, sans-serif; font-size:17pt; font-weight : bold; color : #f43400;">
<xsl:text></xsl:text>
<xsl:value-of select="CoreReturnEmail/CoreReturn/VendorShipItem/VendorOrderItem/VendorOrder/OrderNumber" />
</span>
<br />
<br />
<span style="font-family : Arial, sans-serif;font-size:14pt;">Hello <xsl:if test="CoreReturnEmail/CoreReturn/VendorShipItem/VendorOrderItem/VendorOrder/Order"><xsl:text></xsl:text><xsl:value-of select="CoreReturnEmail/CoreReturn/VendorShipItem/VendorOrderItem/VendorOrder/Order/ShipToFirstName" /></xsl:if>,</span>
<br />
<br />
<span style="font-family : Arial, sans-serif;font-size:14pt;"> This email communication is to provide the information necessary to make your core return fast and easy. <br /><br /> To complete your core return, please email <a href="mailto:othershared@company.com">otherShared@company.com</a>. </span>
<br />
<br />
<br />
<table style="background-color:#dfedf3;" cellpadding="5">
<tr>
<td style="font-size:9pt;font-weight:bold;">Core For:</td>
<td style="font-family : Arial, sans-serif;font-size:9pt;">
<xsl:value-of select="CoreReturnEmail/CoreReturn/VendorShipItem/VendorOrderItem/VendorOrder/Order/OrderChannel/ClientProgram/BrandedName" />
</td>
</tr>
<tr>
<td style="font-size:9pt;font-weight:bold;">Part Ship Date:</td>
<td style="font-family : Arial, sans-serif;font-size:9pt;">
<xsl:value-of select="CoreReturnEmail/CoreReturn/VendorShipItem/VendorShipment/ActualShipDate" />
</td>
</tr>
<xsl:for-each select="CoreReturnEmail/CoreReturn/VendorShipItem/VendorOrderItem/VendorOrder/Order/AdditionalInformation">
<xsl:if test="(string-length(Name) > 0) and (string-length(Value) > 0)">
<tr>
<td style="font-size:9pt;font-weight:bold;">
<xsl:value-of select="Name" />:</td>
<td style="font-family : Arial, sans-serif;font-size:9pt;">
<xsl:value-of select="Value" />
</td>
</tr>
</xsl:if>
</xsl:for-each>
<tr>
<td style="font-size:9pt;font-weight:bold;">other Order Number:</td>
<td style="font-family : Arial, sans-serif;font-size:9pt;">
<xsl:value-of select="CoreReturnEmail/CoreReturn/VendorShipItem/VendorOrderItem/VendorOrder/OrderNumber" />
</td>
</tr>
</table>
<br />
<br />
<br />
<xsl:apply-templates select="CoreReturnEmail/CoreReturn/VendorShipItem" />
<br />
<table style="width:100%;background-color:#dfedf3;" cellspacing="5">
<tr>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:17pt; font-weight : bold; color : #1f415c;">Customer Service</td>
<td style="width:65%">
<hr style="width:100%;border:1px solid #5165a3;" />
</td>
</tr>
<tr>
<td colspan="2" style="font-family : Arial, sans-serif;font-size:12pt;"> Please return cores within <xsl:value-of select="CoreReturnEmail/CoreReturn/VendorShipItem/VendorOrderItem/VendorOrder/Order/OrderChannel/ClientProgram/DaysAllowedForCoreReturn" /> days of part ship date to ensure that claim payments are not affected.<br /><br /> If you have any questions on your core return please email us at <a href="mailto:othershared@company.com">otherShared@company.com</a>.<br /><br /> Please don't reply to this email. Mail sent to this address can't be answered.<br /><br /></td>
</tr>
<tr>
<td colspan="2" style="font-family : Arial, sans-serif;font-size:12pt;">Please click <a href="{/CoreReturnEmail/CoreReturnLabel}" target="_blank">here</a> to view the core return label.</td>
</tr>
</table>
<br />
<br />
<br />
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="CoreReturnEmail/CoreReturn/VendorShipItem">
<table style="width:100%;" cellspacing="0">
<tr style="font-family: Tahoma, Arial, sans-serif; background-color : #34498c; color : white; font-size : 10pt; font-weight : bold;">
<td style="padding:5px;">Brand</td>
<td style="padding:5px;white-space:nowrap;">Part No.</td>
<td style="padding:5px;">Description</td>
<td style="padding:5px;">Status</td>
<td style="padding:5px;">Qty.</td>
<td style="padding:5px;white-space:nowrap;">Core Charge</td>
</tr>
<tr>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:9pt; border-left : 2px solid #dfedf3; border-bottom : 2px solid #dfedf3; padding : 5px;" valign="top">
<xsl:value-of select="VendorOrderItem/OrderItem/otherSKU/Item/Brand/PreferredName" />
</td>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:9pt; border-bottom : 2px solid #dfedf3;padding:5px;" valign="top">
<xsl:value-of select="VendorOrderItem/OrderItem/otherSKU/Item/DisplayNumber" />
</td>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:9pt; border-bottom : 2px solid #dfedf3;padding:5px;" valign="top">
<xsl:if test="string(VendorOrderItem/OrderItem/otherSKU/Item/Description)">
<xsl:value-of select="VendorOrderItem/OrderItem/otherSKU/Item/Description" />
</xsl:if>
</td>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:9pt; border-bottom : 2px solid #dfedf3;padding:5px;" valign="top">
<xsl:value-of select="VendorOrderItem/OrderItem/OrderItemState/Name" />
</td>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:9pt; border-bottom : 2px solid #dfedf3;text-align:right;padding:5px;" valign="top">
<xsl:value-of select="Quantity" />
</td>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:9pt; border-right : 2px solid #dfedf3; border-bottom : 2px solid #dfedf3; padding : 5px;font-weight:bold;padding:5px;text-align:right;" valign="top">
<xsl:value-of select="format-number(VendorOrderItem/OrderItem/CoreCharge, '$###,##0.00')" />
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
转换为:
<html>
<head>
<title>Your Core Has Been Received</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="font-family : Arial, sans-serif;">
<table width="700" cellspacing="0" cellpadding="0">
<tr>
<td>
<img src="http://content.gif" border="0">
<br>
<br>
<span style="font-family : Tahoma, Arial, sans-serif; font-size:21pt; font-weight : bold; color : #1f415c;">Core Return:</span>
<span style="font-family : Tahoma, Arial, sans-serif; font-size:17pt; font-weight : bold; color : #1f415c;"> Order #</span>
<span style="font-family : Tahoma, Arial, sans-serif; font-size:17pt; font-weight : bold; color : #f43400;">12345678</span>
<br>
<br>
<span style="font-family : Arial, sans-serif;font-size:14pt;">Hello CHICAGO,</span>
<br>
<br>
<span style="font-family : Arial, sans-serif;font-size:14pt;"> This email communication is to provide the information necessary to make your core return fast and easy. <br>
<br> To complete your core return, please email <a href="mailto:othershared@company.com">otherShared@company.com</a>. </span>
<br>
<br>
<br>
<table style="background-color:#dfedf3;" cellpadding="5">
<tr>
<td style="font-size:9pt;font-weight:bold;">Core For:</td>
<td style="font-family : Arial, sans-serif;font-size:9pt;"/>
</tr>
<tr>
<td style="font-size:9pt;font-weight:bold;">Part Ship Date:</td>
<td style="font-family : Arial, sans-serif;font-size:9pt;">5/31/2016</td>
</tr>
<tr>
<td style="font-size:9pt;font-weight:bold;">other Order Number:</td>
<td style="font-family : Arial, sans-serif;font-size:9pt;">12345678</td>
</tr>
</table>
<br>
<br>
<br>
<table style="width:100%;" cellspacing="0">
<tr style="font-family: Tahoma, Arial, sans-serif; background-color : #34498c; color : white; font-size : 10pt; font-weight : bold;">
<td style="padding:5px;">Brand</td>
<td style="padding:5px;white-space:nowrap;">Part No.</td>
<td style="padding:5px;">Description</td>
<td style="padding:5px;">Status</td>
<td style="padding:5px;">Qty.</td>
<td style="padding:5px;white-space:nowrap;">Core Charge</td>
</tr>
<tr>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:9pt; border-left : 2px solid #dfedf3; border-bottom : 2px solid #dfedf3; padding : 5px;" valign="top"/>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:9pt; border-bottom : 2px solid #dfedf3;padding:5px;" valign="top"/>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:9pt; border-bottom : 2px solid #dfedf3;padding:5px;" valign="top"/>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:9pt; border-bottom : 2px solid #dfedf3;padding:5px;" valign="top">Sourced</td>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:9pt; border-bottom : 2px solid #dfedf3;text-align:right;padding:5px;" valign="top">1</td>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:9pt; border-right : 2px solid #dfedf3; border-bottom : 2px solid #dfedf3; padding : 5px;font-weight:bold;padding:5px;text-align:right;" valign="top">$40.00</td>
</tr>
</table>
<br>
<table style="width:100%;background-color:#dfedf3;" cellspacing="5">
<tr>
<td style="font-family : Tahoma, Arial, sans-serif; font-size:17pt; font-weight : bold; color : #1f415c;">Customer Service</td>
<td style="width:65%">
<hr style="width:100%;border:1px solid #5165a3;">
</td>
</tr>
<tr>
<td colspan="2" style="font-family : Arial, sans-serif;font-size:12pt;"> Please return cores within days of part ship date to ensure that claim payments are not affected.<br>
<br> If you have any questions on your core return please email us at <a href="mailto:othershared@company.com">otherShared@company.com</a>.<br>
<br> Please don't reply to this email. Mail sent to this address can't be answered.<br>
<br>
</td>
</tr>
<tr>
<td colspan="2" style="font-family : Arial, sans-serif;font-size:12pt;">Please click <a href="https://www.example.com/SomePage.pdf?token=eaf5383bddb9382f5&createdby=f01ddedb0aedd87fe44b9b9b741" target="_blank">here</a> to view the core return label.</td>
</tr>
</table>
<br>
<br>
<br>
</td>
</tr>
</table>
</body>
</html>
正如您所看到的,这非常有效。 CoreReturnLabel URL显示在在线XSL转换以及NotePad ++的XSL转换中。但是,它通过初始代码的那一刻:
XslTransform vXslTransform = new XslTransform();
XmlReader vReader = new XmlTextReader(new StringReader(this.Xslt));
vXslTransform.Load(vReader,null as XmlResolver, null as System.Security.Policy.Evidence);
StringWriter vStringWriter = new StringWriter();
vXslTransform.Transform(this.XmlDocument, null, vStringWriter, null);
...网址为空。
为什么?
答案 0 :(得分:0)
对不起我没有将运行Transform的最新应用程序部署到服务器。当我这样做时,这很好用。
因此,原来的问题实际上是正确答案。