如何在包含&;的xml上编写xslt;lt&;燃气轮机;而不是'<';和'&燃气轮机';
例如,我正在调用一个web服务,它会给我以下响应:如何在包含&;的xml上编写xslt;lt&;燃气轮机;而不是'<';和'&燃气轮机';,xml,xslt,Xml,Xslt,例如,我正在调用一个web服务,它会给我以下响应: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.or
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<executeResponse>
<executeReturn>
<Message>
<Body>
<Clients>
<Client>
<ClientID>C000001</ClientID>
</Client>
<Client>
<ClientID>C000002</ClientID>
</Client>
</Clients>
</Body>
</Message>
</executeReturn>
<executeResponse>
</soapenv:Body>
</soapenv:Envelope>
消息
身体
客户
客户
ClientIDC000001/ClientID
/客户
客户
ClientIDC000002/ClientID
/客户
/客户
/身体
/信息
如何编写XSLT,以便将响应转换为:
<Customers>
<Customer>
<CustomerID>C000001<CustomerID>
<CustomerID>C000002<CustomerID>
<Customer>
<Customers>
C000001
C000002
如果您可以访问像Saxon 9.8这样的XSLT 3处理器,那么您可以使用parse xml
函数将转义标记解析为xml节点,然后将它们转换为xml节点
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:mode on-no-match="text-only-copy"/>
<xsl:template match="executeReturn">
<xsl:apply-templates select="parse-xml(.)"/>
</xsl:template>
<xsl:template match="Clients">
<Customers>
<Customer>
<xsl:apply-templates/>
</Customer>
</Customers>
</xsl:template>
<xsl:template match="ClientID">
<CustomerID>
<xsl:apply-templates/>
</CustomerID>
</xsl:template>
</xsl:stylesheet>
将您的输入转换为
C000001
C000002
对于早期版本的XSLT,您需要检查处理器是否提供扩展功能或允许您实现扩展功能,或者您需要编写两个XSLT样式表,其中第一个样式表使用
禁用输出转义
输出转义标记,第二个样式表然后转换第一个样式表的输出。您不能替换为<和>,使用字符串替换函数?
<?xml version="1.0" encoding="UTF-8"?>
<Customers>
<Customer>
<CustomerID>C000001</CustomerID>
<CustomerID>C000002</CustomerID>
</Customer>
</Customers>