有谁知道为什么XSLT转换会在输出(html)中添加一些不在XSL模板中的内容?
查看下面的示例,我试图摆脱日期(请参阅输出)。
xsl模板
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:php="http://php.net/xsl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:a="http://schemas.datacontract.org/2004/Common.Akol"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<!-- Edited by Adrian -->
<xsl:output method="html" encoding="UTF-8" indent="yes"/>
<xsl:template match="GetDriverDataResult">
<hr />
trans key:
<xsl:value-of select="a:driverInformationResponse/a:TransKey" />
trans key 2:
<xsl:value-of select="a:driverInformationResponse/a:TransKey" />
</xsl:template>
</xsl:stylesheet>
XML
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
<u:Timestamp u:Id="_0">
<u:Created>2014-08-27T00:29:39.204Z</u:Created>
<u:Expires>2014-08-27T00:34:39.204Z</u:Expires>
</u:Timestamp>
</o:Security>
</s:Header>
<s:Body>
<GetDriverDataResponse>
<GetDriverDataResult xmlns:a="http://schemas.datacontract.org/2004/Common.Akol" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:driverInformationResponse>
<a:TransKey>C00029540</a:TransKey>
<a:Status>Success</a:Status>
</a:driverInformationResponse>
</GetDriverDataResult>
</GetDriverDataResponse>
</s:Body>
</s:Envelope>
OUPUT
2014-08-27T00:29:39.204Z
2014-08-27T00:34:39.204Z
trans key:
C00029540
trans key 2:
C00029540
答案 0 :(得分:1)
默认情况下,built-in template rules将文本节点复制到输出XML文档。
要抑制此行为,请添加此模板以匹配文本节点,并且不对它们执行任何操作:
<xsl:template match="text()"/>