2016-12-02 7 views
0

Stack Overflowと@ michael.hor257kのおかげで、私はXML文書で名前空間を正常に更新できました。XSLTを使用してXMLの選択ノードから選択的な名前空間を削除する

ここで問題は1つだけです。
私のSAPシステムは、XSDからのいくつかのフィールドを理解できず、XMLスキーマに対応するために独自の名前空間を追加しました。

これはSAPを通じて解決できますが、まだそのソフトウェア(SPROXY)はインストールされていません。

したがって、私はXSLT 1.0を使用してこれを達成する必要があります。

私の元のXMLました:

<?xml version="1.0" encoding="UTF-8"?> 

<n0:eCPR xmlns:prx="urn:sap.com:proxy:DV4:/1SAI/TAS1F59A417878D36573F1D:700:2013/05/24" xmlns:n0="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd"> 

<n0:employees> 
    <n0:employee> 
    <n0:name id="20019768">Paul John</n0:name> 
</n0:employee> 
</n0:employees> 
</n0:eCPR> 

、以下に必要な出力を達成するために使用されるXSLT:現在のネームスペースと私のXMLを更新した後

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

    <xsl:template match="*"> 
    <xsl:element name="CPR:{local-name()}"> 
    <xsl:copy-of select="@*"/> 
    <xsl:apply-templates/> 
    </xsl:element> 
    </xsl:template> 

を(エラーはそうです)

<?xml version="1.0" encoding="UTF-8"?> 
<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd"> 
<CPR:projectInfo> 
    <CPR:awardingBody xmlns:asx="http://www.sap.com/abapxml" asx:root=""/> 
    <CPR:contractAgencyID xmlns:asx="http://www.sap.com/abapxml" asx:root=""/> 
    <CPR:contractAgency/> 
    <CPR:projectName xmlns:asx="http://www.sap.com/abapxml" asx:root=""/> 
    <CPR:projectID/> 
    <CPR:awardingBodyID/> 
    <CPR:projectNum/> 
    <CPR:contractID/> 

だから、ノードawardingBodycontractAgencyIDProject Nameが正しくシステムによって変換されてしまったことができませんでしたフィールドです。(xmlns:asx名前空間を持つノード)

私はこれらの名前空間を削除する必要があります。 XSLTを通して可能ですか?条件:名前空間http://www.sap.com/abapxmlであるか、私は(彼らが固定されているとして)ノードの名前を提供することができますエントリのみの名前空間を削除する

理想的な構造はどうあるべきか:

<?xml version="1.0" encoding="UTF-8"?> 
<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd"> 
<CPR:projectInfo> 
    <CPR:awardingBody/> 
    <CPR:contractAgencyID /> 
    <CPR:contractAgency/> 
    <CPR:projectName/> 
    <CPR:projectID/> 
    <CPR:awardingBodyID/> 
    <CPR:projectNum/> 
    <CPR:contractID/> 

おかげ

+0

XSLT 1.0または2.0を指定してください。 –

+0

@MichaelKay XSLT 1.0 –

+0

これは非常に混乱しています。最初のXMLは変換の入力ですか?あなたのこれまでの2つの質問に基づいて、私はそれが出力であると思われます。入力内容を表示してください。 –

答えて

1

I推測していますあなたのオリジナルのXMLは、実際にこのような何かに見えること(!):

XMLを

その どんな属性を削除する

<xsl:copy-of select="@*[not(namespace-uri())]"/> 

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:template match="*"> 
    <xsl:element name="CPR:{local-name()}"> 
    <xsl:copy-of select="@*[not(namespace-uri()='http://www.sap.com/abapxml')]"/> 
     <xsl:apply-templates/> 
    </xsl:element> 
</xsl:template> 

</xsl:stylesheet> 

それとも、実行します。あなたがする必要がある - asx:root属性をコピーすることなく、すなわち - 要求された出力を得るために

<n0:eCPR xmlns:n0="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd" xmlns:asx="http://www.sap.com/abapxml"> 
    <n0:projectInfo> 
     <n0:awardingBody asx:root=""/> 
     <n0:contractAgencyID asx:root=""/> 
     <n0:contractAgency/> 
     <n0:projectName asx:root=""/> 
     <n0:projectID/> 
     <n0:awardingBodyID/> 
     <n0:projectNum/> 
     <n0:contractID/> 
    </n0:projectInfo> 
</n0:eCPR> 

名前空間にない

+0

@micheal Perfect ..全体の問題は修正されています。すべてのあなたの返信と説明をありがとう。 –

関連する問題