如何删除xmlns =""来自xml使用xslt

时间:2015-10-03 11:03:13

标签: xml xslt namespaces

我必须以下面的格式生成xml -

    <?xml version="1.0" encoding="utf-8"?>
<ns0:ZINVS xmlns:ns0="http://STATOIL_BarcodeScanning_Schema">
  <CommonFields>
    <CompanyCode>02605</CompanyCode>
    <ScannerID>DST10739:Sess 2</ScannerID>
    <ScanningDate>2015-08-05</ScanningDate>
    <ScanningDocumentDescription>SPLITS0508</ScanningDocumentDescription>
    <ScanningDocumentID>299876_ILOLEJ</ScanningDocumentID>
    <ScanningOperatorID>ILOLEJ</ScanningOperatorID>
    <ScanningTime>15:16:09</ScanningTime>
  </CommonFields>
  <SpecificFields>
<DocumentNumber>15000560</DocumentNumber>
<DocumentType>JL</DocumentType>
<FiscalYear>15</FiscalYear>
<LineNo>1.000</LineNo>
<UserID>ILOLEJ</UserID>
<BarcodeNumber>7882</BarcodeNumber>
<DocumentID>7882</DocumentID>

但是当生成xml时,它就像 -

<?xml version="1.0" encoding="utf-8"?>
<ns0:ZINVS xmlns:ns0="http://STATOIL_BarcodeScanning_Schema" xmlns="http://www.w3.org/2001/XMLSchema" >
  <CommonFields>
    <CompanyCode>02605</CompanyCode>
    <ScannerID>DST10739:Sess 2</ScannerID>
    <ScanningDate>2015-08-05</ScanningDate>
    <ScanningDocumentDescription>SPLITS0508</ScanningDocumentDescription>
    <ScanningDocumentID>299876_ILOLEJ</ScanningDocumentID>
    <ScanningOperatorID>ILOLEJ</ScanningOperatorID>
    <ScanningTime>15:16:09</ScanningTime>
  </CommonFields> 
  <SpecificFields>
    <DocumentNumber>15000560</DocumentNumber>
    <DocumentType>JL</DocumentType>
    <FiscalYear>15</FiscalYear>
    <LineNo>1.000</LineNo>
    <UserID>ILOLEJ</UserID>
    <BarcodeNumber>7882</BarcodeNumber>
    <DocumentID>7882</DocumentID>
 </SpecificFields>
</ns0:ZINVS>

另外,找到XSD为 -

<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://STATOIL_BarcodeScanning_Schema"
            targetNamespace="http://STATOIL_BarcodeScanning_Schema" elementFormDefault="qualified">
  <xsd:element name="ZINVS">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="CommonFields">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="CompanyCode" type="xsd:integer"/>
              <xsd:element name="ScannerID" type="xsd:string"/>
              <xsd:element name="ScanningDate" type="xsd:string"/>
              <xsd:element name="ScanningDocumentDescription" type="xsd:string"/>
              <xsd:element name="ScanningDocumentID" type="xsd:string"/>
              <xsd:element name="ScanningOperatorID" type="xsd:string"/>
              <xsd:element name="ScanningTime" type="xsd:string"/>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
        <xsd:element name="SpecificFields">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="DocumentNumber" type="xsd:integer"/>
              <xsd:element name="DocumentType" type="xsd:string"/>
              <xsd:element name="FiscalYear" type="xsd:integer"/>
              <xsd:element name="LineNo" type="xsd:float"/>
              <xsd:element name="UserID" type="xsd:string"/>
              <xsd:element name="BarcodeNumber" type="xsd:integer"/>
              <xsd:element name="DocumentID" type="xsd:integer"/>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

和XSLT映射为 -

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
                xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
                xmlns:oraxsl="http://www.oracle.com/XSL/Transform/java"
                xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
                xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
                xmlns:tns="http://xmlns.oracle.com/pcbpel/adapter/db/top/dbService" xmlns:xsi="http://xmlns.oracle.com/pcbpel/adapter/db/top/dbService"
                xmlns:oracle-xsl-mapper="http://www.oracle.com/xsl/mapper/schemas"
                xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ns0="http://STATOIL_BarcodeScanning_Schema"
                xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
                exclude-result-prefixes="xsi oracle-xsl-mapper xsl xsd ns0 tns xp20 oraxsl mhdr oraext dvm xref socket"
                >
  <oracle-xsl-mapper:schema>
    <!--SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY.-->
    <oracle-xsl-mapper:mapSources>
      <oracle-xsl-mapper:source type="WSDL">
        <oracle-xsl-mapper:schema location="../WSDLs/dbService.wsdl"/>
        <oracle-xsl-mapper:rootElement name="XmldemoCollection"
                                       namespace="http://xmlns.oracle.com/pcbpel/adapter/db/top/dbService"/>
      </oracle-xsl-mapper:source>
    </oracle-xsl-mapper:mapSources>
    <oracle-xsl-mapper:mapTargets>
      <oracle-xsl-mapper:target type="WSDL">
        <oracle-xsl-mapper:schema location="../WSDLs/fileReference.wsdl"/>
        <oracle-xsl-mapper:rootElement name="ZINVS" namespace="http://STATOIL_BarcodeScanning_Schema"/>
      </oracle-xsl-mapper:target>
    </oracle-xsl-mapper:mapTargets>
    <!--GENERATED BY ORACLE XSL MAPPER 12.1.3.0.0(XSLT Build 140529.0700.0211) AT [SAT OCT 03 16:01:58 IST 2015].-->
  </oracle-xsl-mapper:schema>
  <!--User Editing allowed BELOW this line - DO NOT DELETE THIS LINE-->
  <xsl:template match="/">
    <ns0:ZINVS xmlns="http://www.w3.org/2001/XMLSchema">
      <CommonFields>
        <CompanyCode>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data"/>
        </CompanyCode>
        <ScannerID>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data1"/>
        </ScannerID>
        <ScanningDate>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data2"/>
        </ScanningDate>
        <ScanningDocumentDescription>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data3"/>
        </ScanningDocumentDescription>
        <ScanningDocumentID>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data4"/>
        </ScanningDocumentID>
        <ScanningOperatorID>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data5"/>
        </ScanningOperatorID>
        <ScanningTime>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data6"/>
        </ScanningTime>
      </CommonFields>
      <SpecificFields>
        <DocumentNumber>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data6"/>
        </DocumentNumber>
        <DocumentType>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data6"/>
        </DocumentType>
        <FiscalYear>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data6"/>
        </FiscalYear>
        <LineNo>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data6"/>
        </LineNo>
        <UserID>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data6"/>
        </UserID>
        <BarcodeNumber>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data6"/>
        </BarcodeNumber>
        <DocumentID>
          <xsl:value-of select="/tns:XmldemoCollection/tns:Xmldemo/tns:data6"/>
        </DocumentID>
      </SpecificFields>
    </ns0:ZINVS>
  </xsl:template>
</xsl:stylesheet>

我想删除xmlns =&#34; http://www.w3.org/2001/XMLSchema"从ZINVS元素使用XSLT作为映射是使用XSLT完成的。我不知道我在哪里犯错误,因为我是新手。你们能请我摆脱这个问题吗?

2 个答案:

答案 0 :(得分:0)

在您的XSLT更改中

<ns0:ZINVS xmlns="http://www.w3.org/2001/XMLSchema">

<ns0:ZINVS>

答案 1 :(得分:0)

您需要从xml中删除默认命名空间,正确的语法是空的默认命名空间,如下所示:

<ns0:ZINVS xmlns="">