2012-10-20 18 views
8

Sorunum, XSLT kullanarak tüm öğeler ve özniteliklerin ad alanı ve önekinin nasıl eklenir? Benim girdi xml olduğu gibi ....XSLT kullanarak tüm elemanlar ve özellikler için ad alanı ve önek nasıl eklenir?

<ProcessCreditMemo xmlns='CreditMemo' 
        xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
        xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
        xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> 
<ORDER_HEADERDetails> 
    <ORDER_HEADER> 
    <NAME>0010185214</NAME> 

olmak ...

<ns0:ProcessCreditMemo xmlns='CreditMemo' 
         xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
         xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
         xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' 
         xmlns:ns0="http://tempuri.org/"> 
<ns0:ORDER_HEADERDetails> 
    <ns0:ORDER_HEADER> 
    <ns0:NAME>0010185214</NAME> 

Ben öneki "ns0:" add gereken tüm unsurları ve nitelikleri ve "xmlns ad ekleyin :. ns0 = "http://tempuri.org/" başlığının "ProcessCreditMemo"

bunu yapmak için bir XSLT kurmaya çalışıyorum ... lütfen

<xsl:stylesheet version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<xsl:output method="xml" encoding="UTF-8" indent="yes"/> 
<xsl:template match="node()|text()|@*"> 
    <xsl:copy> 
     <xsl:if test="local-name()='ProcessCreditMemo'"> 
      <xsl:attribute name="xmlns" namespace="http://tempuri.org/" /> 
     </xsl:if> 

ancak ortaya çıkan XML, öneki boş değerle kopyalar.

<ProcessCreditMemo xmlns="CreditMemo" 
        xmlns:ns0="http://tempuri.org/" 
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        ns0:xmlns=""> 

cevap

13

Bu dönüşüm:

<ProcessCreditMemo xmlns='CreditMemo' 
    xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
    xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> 
    <ORDER_HEADERDetails> 
    <ORDER_HEADER> 
     <NAME>0010185214</NAME> 
    </ORDER_HEADER> 
    </ORDER_HEADERDetails> 
</ProcessCreditMemo> 

istenen üretir: (düzeltilmiş) ile

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:ns0="http://tempuri.org/"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:template match="node()|@*"> 
    <xsl:copy> 
     <xsl:apply-templates select="node()|@*"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="*"> 
    <xsl:element name="ns0:{name()}" namespace="http://tempuri.org/"> 
    <xsl:copy-of select="namespace::*"/> 
     <xsl:apply-templates select="node()|@*"/> 
    </xsl:element> 
</xsl:template> 
</xsl:stylesheet> 

uygulanır (ağır hatalı biçimlendirilmiş, eksik XML) giriş Resim Doğru sonuç (ciddi biçimde hatalı/eksik verilen istenen sonuç değil)):

<ns0:ProcessCreditMemo xmlns:ns0="http://tempuri.org/" xmlns="CreditMemo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <ns0:ORDER_HEADERDetails> 
     <ns0:ORDER_HEADER> 
     <ns0:NAME>0010185214</ns0:NAME> 
     </ns0:ORDER_HEADER> 
    </ns0:ORDER_HEADERDetails> 
</ns0:ProcessCreditMemo> 
+0

benim XSLT'de benzer kod parçacığını kullanıyorum ama benim Tutulma .... hata mesaj olarak geçersiz xpath gösteren tutar .. Ancak, xml dönüştürme mükemmel çalışıyor. –

İlgili konular