我是XSLT的新手并且在命名空间方面存在问题。 这是我要转换的XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://www.softomat.bg/myapp/esb/ServiceOrderToTechnicalOrderTransformer">
<soapenv:Header/>
<soapenv:Body>
<InputRequestID>?</InputRequestID>
<InputTimeStamp>?</InputTimeStamp>
<OrderInput>
<Recipient>?</Recipient>
<PortInFlag>?</PortInFlag>
<Donor>?</Donor>
<FMCFirstCompleteFlag>?</FMCFirstCompleteFlag>
<CreatedOn>?</CreatedOn>
<ACSBillingAccountIntegId>?</ACSBillingAccountIntegId>
<OrderType>?</OrderType>
<OrderReason>?</OrderReason>
<CustomerFirstName>?</CustomerFirstName>
<CustomerName>?</CustomerName>
<AgreementNum>?</AgreementNum>
<AgreedbyOwner>?</AgreedbyOwner>
<OriginalReceived>?</OriginalReceived>
<AgreementSignDate>?</AgreementSignDate>
<BusinessContactFirstName>?</BusinessContactFirstName>
<BusinessContactLastName>?</BusinessContactLastName>
<UserID>?</UserID>
<FMCMNPRequestId>?</FMCMNPRequestId>
<LegalContactFirstName>?</LegalContactFirstName>
<LegalContactLastName>?</LegalContactLastName>
<CreatedBy>?</CreatedBy>
<Comments>?</Comments>
<IntegrationID>?</IntegrationID>
<OrderId>?</OrderId>
<ReferenceOrder>?</ReferenceOrder>
<Status>?</Status>
<OrderTypeProvisioningRelevant>?</OrderTypeProvisioningRelevant>
<TriggerScript>?</TriggerScript>
<OrderSource>?</OrderSource>
<CustomerSegment>?</CustomerSegment>
<CustomerSubsegment>?</CustomerSubsegment>
<CustomerIdNumber>?</CustomerIdNumber>
<CustomerIdType>?</CustomerIdType>
<Priority>?</Priority>
<CustomerCode>?</CustomerCode>
<Urgent>?</Urgent>
<SalesPersonEmail>?</SalesPersonEmail>
<NotificationPhoneNumber>?</NotificationPhoneNumber>
<NotificationEmail>?</NotificationEmail>
<ASAP>?</ASAP>
<CustomerNotificationChannel>?</CustomerNotificationChannel>
<OrderCreatorEmail>?</OrderCreatorEmail>
<PrevCustomerRef>?</PrevCustomerRef>
<VIPFlag>?</VIPFlag>
</OrderInput>
</soapenv:Body>
</soapenv:Envelope>
我使用以下XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ser="http://www.softomat.bg/myapp/esb/ServiceOrderToTechnicalOrderTransformer" version="2.0">
<xsl:output method="xml" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://bre-sc/ServiceOrderToTechnicalOrderTransformer">
<soapenv:Body>
<ser:ServiceOrderToTechnicalOrderTransformerRequest>
<xsl:copy-of select="soapenv:Envelope/soapenv:Body/OrderInput" />
</ser:ServiceOrderToTechnicalOrderTransformerRequest>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
结果是:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://bre-sc/ServiceOrderToTechnicalOrderTransformer">
<soapenv:Body>
<ser:ServiceOrderToTechnicalOrderTransformerRequest>
<OrderInput **xmlns:ser="http://www.softomat.bg/myapp/esb/ServiceOrderToTechnicalOrderTransformer"**>
<Recipient>
?
</Recipient>
<PortInFlag>
?
</PortInFlag>
<Donor>
?
</Donor>
<FMCFirstCompleteFlag>
?
</FMCFirstCompleteFlag>
<CreatedOn>
?
</CreatedOn>
<ACSBillingAccountIntegId>
?
</ACSBillingAccountIntegId>
<OrderType>
?
</OrderType>
<OrderReason>
?
</OrderReason>
<CustomerFirstName>
?
</CustomerFirstName>
<CustomerName>
?
</CustomerName>
<AgreementNum>
?
</AgreementNum>
<AgreedbyOwner>
?
</AgreedbyOwner>
<OriginalReceived>
?
</OriginalReceived>
<AgreementSignDate>
?
</AgreementSignDate>
<BusinessContactFirstName>
?
</BusinessContactFirstName>
<BusinessContactLastName>
?
</BusinessContactLastName>
<UserID>
?
</UserID>
<FMCMNPRequestId>
?
</FMCMNPRequestId>
<LegalContactFirstName>
?
</LegalContactFirstName>
<LegalContactLastName>
?
</LegalContactLastName>
<CreatedBy>
?
</CreatedBy>
<Comments>
?
</Comments>
<IntegrationID>
?
</IntegrationID>
<OrderId>
?
</OrderId>
<ReferenceOrder>
?
</ReferenceOrder>
<Status>
?
</Status>
<OrderTypeProvisioningRelevant>
?
</OrderTypeProvisioningRelevant>
<TriggerScript>
?
</TriggerScript>
<OrderSource>
?
</OrderSource>
<CustomerSegment>
?
</CustomerSegment>
<CustomerSubsegment>
?
</CustomerSubsegment>
<CustomerIdNumber>
?
</CustomerIdNumber>
<CustomerIdType>
?
</CustomerIdType>
<Priority>
?
</Priority>
<CustomerCode>
?
</CustomerCode>
<Urgent>
?
</Urgent>
<SalesPersonEmail>
?
</SalesPersonEmail>
<NotificationPhoneNumber>
?
</NotificationPhoneNumber>
<NotificationEmail>
?
</NotificationEmail>
<ASAP>
?
</ASAP>
<CustomerNotificationChannel>
?
</CustomerNotificationChannel>
<OrderCreatorEmail>
?
</OrderCreatorEmail>
<PrevCustomerRef>
?
</PrevCustomerRef>
<VIPFlag>
?
</VIPFlag>
</OrderInput>
</ser:ServiceOrderToTechnicalOrderTransformerRequest>
</soapenv:Body>
我试图删除结果的InputOrder中的命名空间,但它对我不起作用。任何人都可以帮助我使用XSLT吗?感谢。
答案 0 :(得分:0)
这可以通过在样式表中进行如下的微小更改来实现。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ser1="http://bre-sc/ServiceOrderToTechnicalOrderTransformer"
xmlns:ser="http://www.softomat.bg/myapp/esb/ServiceOrderToTechnicalOrderTransformer">
<soapenv:Body>
<ser:ServiceOrderToTechnicalOrderTransformerRequest>
<xsl:copy-of select="soapenv:Envelope/soapenv:Body/OrderInput" />
</ser:ServiceOrderToTechnicalOrderTransformerRequest>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
</xsl:stylesheet>
我已将xmlns:ser
内的<soapenv:Envelope>
移至<xsl:stylesheet>
节点,并为现有网址创建了单独的别名xmlns:ser1
。这将确保应用的命名空间成为父节点的属性。输出转换的XML如下所示。
<soapenv:Envelope
xmlns:ser="http://www.softomat.bg/myapp/esb/ServiceOrderToTechnicalOrderTransformer"
xmlns:ser1="http://bre-sc/ServiceOrderToTechnicalOrderTransformer"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ser:ServiceOrderToTechnicalOrderTransformerRequest>
<OrderInput>
<Recipient>?</Recipient>
<PortInFlag>?</PortInFlag>
<Donor>?</Donor>
<FMCFirstCompleteFlag>?</FMCFirstCompleteFlag>
<CreatedOn>?</CreatedOn>
<ACSBillingAccountIntegId>?</ACSBillingAccountIntegId>
<OrderType>?</OrderType>
<OrderReason>?</OrderReason>
<CustomerFirstName>?</CustomerFirstName>
<CustomerName>?</CustomerName>
<AgreementNum>?</AgreementNum>
<AgreedbyOwner>?</AgreedbyOwner>
<OriginalReceived>?</OriginalReceived>
<AgreementSignDate>?</AgreementSignDate>
<BusinessContactFirstName>?</BusinessContactFirstName>
<BusinessContactLastName>?</BusinessContactLastName>
<UserID>?</UserID>
<FMCMNPRequestId>?</FMCMNPRequestId>
<LegalContactFirstName>?</LegalContactFirstName>
<LegalContactLastName>?</LegalContactLastName>
<CreatedBy>?</CreatedBy>
<Comments>?</Comments>
<IntegrationID>?</IntegrationID>
<OrderId>?</OrderId>
<ReferenceOrder>?</ReferenceOrder>
<Status>?</Status>
<OrderTypeProvisioningRelevant>?</OrderTypeProvisioningRelevant>
<TriggerScript>?</TriggerScript>
<OrderSource>?</OrderSource>
<CustomerSegment>?</CustomerSegment>
<CustomerSubsegment>?</CustomerSubsegment>
<CustomerIdNumber>?</CustomerIdNumber>
<CustomerIdType>?</CustomerIdType>
<Priority>?</Priority>
<CustomerCode>?</CustomerCode>
<Urgent>?</Urgent>
<SalesPersonEmail>?</SalesPersonEmail>
<NotificationPhoneNumber>?</NotificationPhoneNumber>
<NotificationEmail>?</NotificationEmail>
<ASAP>?</ASAP>
<CustomerNotificationChannel>?</CustomerNotificationChannel>
<OrderCreatorEmail>?</OrderCreatorEmail>
<PrevCustomerRef>?</PrevCustomerRef>
<VIPFlag>?</VIPFlag>
</OrderInput>
</ser:ServiceOrderToTechnicalOrderTransformerRequest>
</soapenv:Body>
</soapenv:Envelope>