2015-10-03 29 views
-1

我不得不產生如下格式的XML刪除的xmlns = 「」 從XML -如何使用XSLT

<?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> 

我想刪除使用XSLT作爲映射從ZINVS元素的xmlns =「http://www.w3.org/2001/XMLSchema」使用XSLT.I做我不確定我犯了什麼錯誤,因爲我是新來的。你們能請我擺脫這個問題嗎?

+0

你用什麼軟件來生成XML?它不應該將兩個不同的xmlns屬性放入同一個元素中。 – Spudley

+0

您好,我使用Jdeveloper從正確的XML生成XSD。在創建XSD時,我將目標名稱空間設置爲 - http:// STATOIL_BarcodeScanning_Schema。這是問題嗎?我是否只生成wronf XSD? –

回答

0

在你的XSLT變化

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

<ns0:ZINVS> 
+0

你好,如果我不像這樣寫那麼子元素會獲得名稱空間爲xmlns =「」,我仍然可以看到xmlns = 「http://www.w3.org/2001/XMLSchema」在我的根元素中。我不想讓xmlns進入我的根元素和子元素。 –

+0

@kushalkaria你能發佈原始的XML嗎? – wero

0

您需要從XML刪除默認命名空間,這個正確的語法是空的默認命名空間,就像這樣:

<ns0:ZINVS xmlns="">