使用命名空间转换xsl

时间:2014-01-03 13:35:47

标签: xml xslt wso2 transformation

我在尝试转换此XML时遇到了一些麻烦:

 <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
  <soapenv:Body>
   <p:GetAgendamento xmlns:p="http://ws.wso2.org/dataservice">
    <xs:Servico xmlns:xs="http://ws.wso2.org/dataservice">1</xs:Servico>
    <xs:Oportunidade xmlns:xs="http://ws.wso2.org/dataservice">2</xs:Oportunidade>
    <xs:Caso xmlns:xs="http://ws.wso2.org/dataservice">3</xs:Caso>
   </p:GetAgendamento>
  </soapenv:Body>
</soapenv:Envelope>

到此:

<GetAppointment>
  <ServiceOrderID>1</ServiceID>
  <OpportunityID>2</OpportunityID>
  <CaseID>3</CaseID>
</GetAppointment>

但是,使用生成此xsl的工具:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:p="http://ws.wso2.org/dataservice" version="2.0" xpath-default-namespace="http://www.algartelecom.com.br/SOA/Service/GetAppointmentSchedulePortalReqCS">
  <xsl:output method="xml" indent="yes" />
  <xsl:template match="p:GetAgendamento">
    <GetAppointment>
      <xsl:call-template name="_template_0" />
    </GetAppointment>
  </xsl:template>
  <xsl:template name="_template_0">
    <xsl:for-each select="xs:Servico">
      <ServiceOrderID>
        <xsl:apply-templates select="." />
      </ServiceOrderID>
    </xsl:for-each>
    <xsl:for-each select="xs:Oportunidade">
      <OportunityID>
        <xsl:apply-templates select="." />
      </OportunityID>
    </xsl:for-each>
    <xsl:for-each select="xs:Caso">
      <CaseID>
        <xsl:apply-templates select="." />
      </CaseID>
    </xsl:for-each>
  </xsl:template>
</xsl:transform>

结果是:

<?xml version="1.0" encoding="UTF-8"?>
<GetAppointment xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:p="http://ws.wso2.org/dataservice"/>

我想这是由命名空间引起的问题。请帮忙。

1 个答案:

答案 0 :(得分:2)

在你的xsl:xmlns:xs="http://www.w3.org/2001/XMLSchema"

在您的来源xml中:xmlns:xs="http://ws.wso2.org/dataservice"

修正这种差异,它应该会更好。