2017-01-27 18 views
0

現在、ノードレベルに名前空間がないXMLドキュメントがあります。スケルトンドキュメントで定義されている名前空間をコピーできるようにしたいと思います。XSLT:スケルトンからノードに名前空間を追加する

私はNokogiri(Ruby)を使用して文書を処理しており、XSLT 1.0またはその他の実行可能なアプローチが必要です。

これも可能ですか?

文献

<routing 
    xmlns:rt="urn:ietf:params:xml:ns:yang:ietf-routing" 
    xmlns:cisco-ospf="urn:ietf:params:xml:ns:yang:cisco-ospf" 
    xmlns:ospf-devs="http://cisco.com/ns/ietf-ospf/devs" 
    xmlns:ospf="urn:ietf:params:xml:ns:yang:ietf-ospf" 
    xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"> 
    <routing-instance> 
     <name>default</name> 
     <description>default-vrf [read-only]</description> 
     <routing-protocols> 
      <routing-protocol> 
       <type>ospf:ospfv2</type> 
       <name>100</name> 
       <ospf> 
        <instance> 
         <af>rt:ipv4</af> 
         <router-id>6.6.6.6</router-id> 
         <admin-distance> 
          <intra-area>100</intra-area> 
          <inter-area>200</inter-area> 
          <external>10</external> 
         </admin-distance> 
         <auto-cost> 
          <enable>true</enable> 
          <reference-bandwidth>5000</reference-bandwidth> 
         </auto-cost> 
         <area> 
         <area-id>50</area-id> 
         <default-cost>50</default-cost> 
         </area> 
         <area> 
         <area-id>100</area-id> 
         <default-cost>100</default-cost> 
         </area> 
         <area> 
         <area-id>300</area-id> 
         <virtual-link> 
          <router-id>8.8.8.8</router-id> 
          <hello-interval>80</hello-interval> 
         </virtual-link> 
         </area> 
         <area> 
         <area-id>666</area-id> 
         <default-cost>100</default-cost> 
         </area> 
         <redistribution> 
          <static> 
           <redist-option> 
            <metric>99999</metric> 
            <metric-type>1</metric-type> 
           </redist-option> 
          </static> 
         </redistribution> 
        </instance> 
       </ospf> 
      </routing-protocol> 
     </routing-protocols> 
    </routing-instance> 

スケルトン

<routing 
    xmlns:rt="urn:ietf:params:xml:ns:yang:ietf-routing" 
    xmlns:cisco-ospf="urn:ietf:params:xml:ns:yang:cisco-ospf" 
    xmlns:ospf-devs="http://cisco.com/ns/ietf-ospf/devs" 
    xmlns:ospf="urn:ietf:params:xml:ns:yang:ietf-ospf" 
    xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"> 
    <routing-instance xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"> 
    <name xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"/> 
    <router-id xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"/> 
    <description xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"/> 
     <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"> 
     <interface xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"/> 
     </interfaces> 
     <routing-protocols xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"> 
      <routing-protocol xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"> 
      <name xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"/> 
      <static-routes xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"/> 
       <ospf xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"> 
        <instance xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"> 
        <af xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"/> 
        <router-id xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"/> 
         <admin-distance xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"> 
         <intra-area xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"/> 
         <inter-area xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"/> 
         <external xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"/> 
         </admin-distance> 
         <nsr xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"> 
         <enable xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"/> 
         </nsr> 
         <auto-cost xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"> 
         <enable xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"/> 
         <reference-bandwidth xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"/> 
         </auto-cost> 
         <area xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"> 
         <area-id xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"/> 
         <default-cost xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"/> 
         </area> 
         <default-metric xmlns="urn:ietf:params:xml:ns:yang:cisco-ospf"/> 
         <redistribution xmlns="urn:ietf:params:xml:ns:yang:cisco-ospf"> 
          <static xmlns="urn:ietf:params:xml:ns:yang:cisco-ospf"> 
           <redist-option xmlns="urn:ietf:params:xml:ns:yang:cisco-ospf"> 
           <metric xmlns="urn:ietf:params:xml:ns:yang:cisco-ospf"/> 
           <metric-type xmlns="urn:ietf:params:xml:ns:yang:cisco-ospf"/> 
           </redist-option> 
          </static> 
         </redistribution> 
        </instance> 
       </ospf> 
      </routing-protocol> 
     </routing-protocols> 
    </routing-instance> 

所望の出力

<routing 
    xmlns:rt="urn:ietf:params:xml:ns:yang:ietf-routing" 
    xmlns:cisco-ospf="urn:ietf:params:xml:ns:yang:cisco-ospf" 
    xmlns:ospf-devs="http://cisco.com/ns/ietf-ospf/devs" 
    xmlns:ospf="urn:ietf:params:xml:ns:yang:ietf-ospf" 
    xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"> 
    <routing-instance xmlns="urn:ietf:params:xml:ns:yang:ietf-routing"> 
     <name>default</name> 
     <description>default-vrf [read-only]</description> 
     <routing-protocols> 
      <routing-protocol> 
       <type>ospf:ospfv2</type> 
       <name>100</name> 
       <ospf xmlns="urn:ietf:params:xml:ns:yang:ietf-ospf"> 
        <instance> 
         <af>rt:ipv4</af> 
         <router-id>6.6.6.6</router-id> 
         <admin-distance> 
          <intra-area>100</intra-area> 
          <inter-area>200</inter-area> 
          <external>10</external> 
         </admin-distance> 
         <auto-cost> 
          <enable>true</enable> 
          <reference-bandwidth>5000</reference-bandwidth> 
         </auto-cost> 
         <area> 
         <area-id>50</area-id> 
         <default-cost>50</default-cost> 
         </area> 
         <area> 
         <area-id>100</area-id> 
         <default-cost>100</default-cost> 
         </area> 
         <area> 
         <area-id>300</area-id> 
         <virtual-link> 
          <router-id>8.8.8.8</router-id> 
          <hello-interval>80</hello-interval> 
         </virtual-link> 
         </area> 
         <area> 
         <area-id>666</area-id> 
         <default-cost>100</default-cost> 
         </area> 
         <redistribution xmlns="urn:ietf:params:xml:ns:yang:cisco-ospf"> 
          <static> 
           <redist-option> 
            <metric>99999</metric> 
            <metric-type>1</metric-type> 
           </redist-option> 
          </static> 
         </redistribution> 
        </instance> 
       </ospf> 
      </routing-protocol> 
     </routing-protocols> 
    </routing-instance> 

+0

この繰り返しの目的は何ですか?デフォルトの名前空間は継承されます。 –

+0

名前空間はドキュメント全体で変更できます。この特定の例では、2つの名前空間が利用されていますが、大きな文書ではいくつかの名前空間があります。 –

+0

これはかなり混乱しているのではないかと心配しています。まず、出力に示されているように名前空間宣言を繰り返す必要はありません。ルート 'routing'要素と' ospf'要素でのみ必要です。もう一つのパズルはスケルトンドキュメントの役割です。スタイルシートにこれを読んで出力を調整することを望んでいますか?それはXSLT 1.0で実装するのがかなり難しいでしょう。これが本当に必要ですか?名前空間は通常、スキーマによって指示されます。スキーマは通常はあまり変わっていません。 –

答えて

0

ご希望の文書には、多くの冗長な名前空間宣言が含まれています。

XSLTシリアライザに余分な名前空間宣言を出力させる方法はありません。

誰もがそれを望んでいる理由が分かりにくいからです。

あなたの本当の目的は、それらの名前空間を表す冗長な名前空間宣言を出力するのではなく、いくつかのマッピングファイル定義に従って要素の名前空間を変更することです。

関連する問題