SOAP XML 到 XML 使用 xsl
SOAP XML to XML using xsl
我正在尝试使用 XSL 将 SOAP XML 转换为 XML,但是我已经研究这个太久了,无法弄清楚我将如何进行错误的。有什么想法吗?
香皂XML
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="https://XXX.disclosures.co.uk/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:InitiateApplicationResponse>
<InitiateApplicationResponse>
<Application>
<ApplicantReferenceNumber>580064065</ApplicantReferenceNumber>
<Forename>SEASHELLS</Forename>
<Surname>OSEAS</Surname>
<InitiateStatus>SUCCESS</InitiateStatus>
<Error />
<StatusCode>202</StatusCode>
<StatusDescription>e-Invitation Sent</StatusDescription>
<TransactionReferenceNumber>202201310003</TransactionReferenceNumber>
</Application>
</InitiateApplicationResponse>
</ns1:InitiateApplicationResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0">
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="https://XXX.disclosures.co.uk/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<xsl:template match="ns1:InitiateApplicationResponse">
<xsl:for-each select="Application">
<EXCHANGE>
<SPD>
<SPD.SRS>
<SPD_STUC.SPD.SRS>
<xsl:value-of select="ApplicantReferenceNumber" />
</SPD_STUC.SPD.SRS>
<SPD_SEQN.SPD.SRS>CRB</SPD_SEQN.SPD.SRS>
<SPD_UDF1.SPD.SRS>
<xsl:value-of select="TransactionReferenceNumber" />
</SPD_UDF1.SPD.SRS>
</SPD.SRS>
</SPD>
</EXCHANGE>
</xsl:for-each>
</xsl:template>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</xsl:stylesheet>
正在尝试使用上述 SOAP 和 XSL
转换为 XML
<?xml version="1.0" encoding="UTF-8"?>
<EXCHANGE>
<SPD>
<SPD.SRS>
<SPD_STUC.SPD.SRS>580064065</SPD_STUC.SPD.SRS>
<SPD_SEQN.SPD.SRS>CRB</SPD_SEQN.SPD.SRS>
<SPD_UDF1.SPD.SRS>202201310003</SPD_UDF1.SPD.SRS>
</SPD.SRS>
</SPD>
</EXCHANGE>
请尝试以下 XSLT。
XSLT
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Application">
<EXCHANGE>
<SPD>
<SPD.SRS>
<SPD_STUC.SPD.SRS>
<xsl:value-of select="ApplicantReferenceNumber"/>
</SPD_STUC.SPD.SRS>
<SPD_SEQN.SPD.SRS>CRB</SPD_SEQN.SPD.SRS>
<SPD_UDF1.SPD.SRS>
<xsl:value-of select="TransactionReferenceNumber"/>
</SPD_UDF1.SPD.SRS>
</SPD.SRS>
</SPD>
</EXCHANGE>
</xsl:template>
</xsl:stylesheet>
输出XML
<?xml version='1.0' encoding='utf-8' ?>
<EXCHANGE>
<SPD>
<SPD.SRS>
<SPD_STUC.SPD.SRS>580064065</SPD_STUC.SPD.SRS>
<SPD_SEQN.SPD.SRS>CRB</SPD_SEQN.SPD.SRS>
<SPD_UDF1.SPD.SRS>202201310003</SPD_UDF1.SPD.SRS>
</SPD.SRS>
</SPD>
</EXCHANGE>
如果您的消息中还有更多内容,那么只有 SOAP-ENV:Body 并且想知道如何使用 xsl 处理命名空间,这就是您可能需要的:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="https://XXX.disclosures.co.uk/"
exclude-result-prefixes="SOAP-ENV ns1"
version="1.0"
>
<xsl:output indent="yes" method="xml" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates select="SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:InitiateApplicationResponse/InitiateApplicationResponse/Application"/>
</xsl:template>
<xsl:template match="Application">
<EXCHANGE>
<SPD>
<SPD.SRS>
<SPD_STUC.SPD.SRS>
<xsl:value-of select="ApplicantReferenceNumber" />
</SPD_STUC.SPD.SRS>
<SPD_SEQN.SPD.SRS>CRB</SPD_SEQN.SPD.SRS>
<SPD_UDF1.SPD.SRS>
<xsl:value-of select="TransactionReferenceNumber" />
</SPD_UDF1.SPD.SRS>
</SPD.SRS>
</SPD>
</EXCHANGE>
</xsl:template>
</xsl:stylesheet>
我正在尝试使用 XSL 将 SOAP XML 转换为 XML,但是我已经研究这个太久了,无法弄清楚我将如何进行错误的。有什么想法吗?
香皂XML
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="https://XXX.disclosures.co.uk/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:InitiateApplicationResponse>
<InitiateApplicationResponse>
<Application>
<ApplicantReferenceNumber>580064065</ApplicantReferenceNumber>
<Forename>SEASHELLS</Forename>
<Surname>OSEAS</Surname>
<InitiateStatus>SUCCESS</InitiateStatus>
<Error />
<StatusCode>202</StatusCode>
<StatusDescription>e-Invitation Sent</StatusDescription>
<TransactionReferenceNumber>202201310003</TransactionReferenceNumber>
</Application>
</InitiateApplicationResponse>
</ns1:InitiateApplicationResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0">
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="https://XXX.disclosures.co.uk/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<xsl:template match="ns1:InitiateApplicationResponse">
<xsl:for-each select="Application">
<EXCHANGE>
<SPD>
<SPD.SRS>
<SPD_STUC.SPD.SRS>
<xsl:value-of select="ApplicantReferenceNumber" />
</SPD_STUC.SPD.SRS>
<SPD_SEQN.SPD.SRS>CRB</SPD_SEQN.SPD.SRS>
<SPD_UDF1.SPD.SRS>
<xsl:value-of select="TransactionReferenceNumber" />
</SPD_UDF1.SPD.SRS>
</SPD.SRS>
</SPD>
</EXCHANGE>
</xsl:for-each>
</xsl:template>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</xsl:stylesheet>
正在尝试使用上述 SOAP 和 XSL
转换为 XML<?xml version="1.0" encoding="UTF-8"?>
<EXCHANGE>
<SPD>
<SPD.SRS>
<SPD_STUC.SPD.SRS>580064065</SPD_STUC.SPD.SRS>
<SPD_SEQN.SPD.SRS>CRB</SPD_SEQN.SPD.SRS>
<SPD_UDF1.SPD.SRS>202201310003</SPD_UDF1.SPD.SRS>
</SPD.SRS>
</SPD>
</EXCHANGE>
请尝试以下 XSLT。
XSLT
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Application">
<EXCHANGE>
<SPD>
<SPD.SRS>
<SPD_STUC.SPD.SRS>
<xsl:value-of select="ApplicantReferenceNumber"/>
</SPD_STUC.SPD.SRS>
<SPD_SEQN.SPD.SRS>CRB</SPD_SEQN.SPD.SRS>
<SPD_UDF1.SPD.SRS>
<xsl:value-of select="TransactionReferenceNumber"/>
</SPD_UDF1.SPD.SRS>
</SPD.SRS>
</SPD>
</EXCHANGE>
</xsl:template>
</xsl:stylesheet>
输出XML
<?xml version='1.0' encoding='utf-8' ?>
<EXCHANGE>
<SPD>
<SPD.SRS>
<SPD_STUC.SPD.SRS>580064065</SPD_STUC.SPD.SRS>
<SPD_SEQN.SPD.SRS>CRB</SPD_SEQN.SPD.SRS>
<SPD_UDF1.SPD.SRS>202201310003</SPD_UDF1.SPD.SRS>
</SPD.SRS>
</SPD>
</EXCHANGE>
如果您的消息中还有更多内容,那么只有 SOAP-ENV:Body 并且想知道如何使用 xsl 处理命名空间,这就是您可能需要的:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="https://XXX.disclosures.co.uk/"
exclude-result-prefixes="SOAP-ENV ns1"
version="1.0"
>
<xsl:output indent="yes" method="xml" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates select="SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:InitiateApplicationResponse/InitiateApplicationResponse/Application"/>
</xsl:template>
<xsl:template match="Application">
<EXCHANGE>
<SPD>
<SPD.SRS>
<SPD_STUC.SPD.SRS>
<xsl:value-of select="ApplicantReferenceNumber" />
</SPD_STUC.SPD.SRS>
<SPD_SEQN.SPD.SRS>CRB</SPD_SEQN.SPD.SRS>
<SPD_UDF1.SPD.SRS>
<xsl:value-of select="TransactionReferenceNumber" />
</SPD_UDF1.SPD.SRS>
</SPD.SRS>
</SPD>
</EXCHANGE>
</xsl:template>
</xsl:stylesheet>