首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSLT:从骨架中向节点添加名称空间

XSLT:从骨架中向节点添加名称空间
EN

Stack Overflow用户
提问于 2017-01-27 21:54:47
回答 1查看 51关注 0票数 0

我有一个XML文档,它目前在节点级别上缺少名称空间。我希望能够复制框架文档中定义的命名空间。

我正在使用Nokogiri (Ruby)处理文档,并且需要XSLT1.0或任何其他可行的方法。

这有可能吗?

文档

代码语言:javascript
复制
  <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>

骨架

代码语言:javascript
复制
  <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>

期望输出

代码语言:javascript
复制
  <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>

EN

回答 1

Stack Overflow用户

发布于 2017-01-28 00:06:48

您想要的文档包含许多冗余的命名空间声明。

无法强制XSLT序列化程序输出冗余的命名空间声明。

那是因为很难找到任何人想要它们的好理由。

如果您的真正目的是根据某些映射文件定义更改元素的命名空间,而不是输出表示这些名称空间的冗余命名空间声明,那么最好更改示例。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41903649

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档