首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSLT生成不必要的命名空间ver2.0

XSLT生成不必要的命名空间ver2.0
EN

Stack Overflow用户
提问于 2018-05-03 12:53:09
回答 1查看 26关注 0票数 1

我有这样一个xml (FUSE蓝图定义文件):

代码语言:javascript
复制
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
    xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
    xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 
    https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd 
    http://camel.apache.org/schema/blueprint 
    http://camel.apache.org/schema/blueprint/camel-blueprint.xsd           
    http://cxf.apache.org/blueprint/jaxws 
    http://cxf.apache.org/schemas/blueprint/jaxws.xsd           
    http://camel.apache.org/schema/blueprint/cxf 
    http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd          
    http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 
    http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">

...
    <bean class="xxxxx.fuse.util.CommonAuthInterceptor" id="authorizationInterceptor">
       <property name="methodRolesMap">
           <map>
               <entry key="xxxElemE1" value="xxxElemE1Role"/>
               <entry key="xxxTipusE1" value="xxxTipusE1Role"/>
               <entry key="xxxLekerdezE1" value="xxxLekerdezE1Role"/>
               <entry key="xxxValtozasE1" value="xxxValtozasE1Role"/>
           </map>
        </property>
        <property name="globalRoles" value="xxxUsers"/>
    </bean>
...
    <camelContext id="xxxContext" xmlns="http://camel.apache.org/schema/blueprint">
        <route id="xxxModositE1_Route" streamCache="true">
            <from id="xxxModositE1_from1" uri="cxf:bean:xxxModositE1_LocalEndpoint?dataFormat=PAYLOAD"/>
            <convertBodyTo id="xxxModositE1_convertBodyTo1" type="java.lang.String"/>
            <wireTap id="xxxModositE1_wireTap1" uri="direct-vm:logRequest"/>
            <to id="xxxModositE1_to2" uri="cxf:bean:xxxModositE1_RemoteEndpoint?dataFormat=PAYLOAD"/>
            <convertBodyTo id="xxxModositE1_convertBodyTo3" type="java.lang.String"/>
            <wireTap id="xxxModositE1_wireTap3" uri="direct-vm:logResponse"/>
        </route>
        ...
     </camelContext>
</blueprint>

我必须在最后一项和最后一条路线之后添加新元素。问题是xslt在新添加的路由元素中生成额外的命名空间定义,而不是在条目中。这是xslt的相关部分:

代码语言:javascript
复制
<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
    exclude-result-prefixes="xsd">

    <xsl:param name="service-name"/>
    <xsl:output omit-xml-declaration="yes" indent="yes"/>

...
    <xsl:template match="*:map/*:entry[last()]">     
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>       
        </xsl:copy>
        <entry key="{$service-name}" value="{$service-name}Role"/>
    </xsl:template>
...

   <xsl:template match="*:camelContext/*:route[last()]">
       <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>        
       </xsl:copy>
       <route id="{$service-name}_xslt_Route" streamCache="true">
             <from id="{$service-name}_from1" uri="cxf:bean:{$service-name}_LocalEndpoint?dataFormat=PAYLOAD"/>
             <convertBodyTo id="{$service-name}_convertBodyTo1" type="java.lang.String"/>
             <wireTap id="{$service-name}_wireTap1" uri="direct-vm:logRequest"/>
             <to id="{$service-name}_to2" uri="cxf:bean:{$service-name}_RemoteEndpoint?dataFormat=PAYLOAD"/>
             <convertBodyTo id="{$service-name}_convertBodyTo3" type="java.lang.String"/>
            <wireTap id="{$service-name}_wireTap3" uri="direct-vm:logResponse"/>
        </route>
    </xsl:template>
<xsl:stylesheet>

条目的输出是正确的,其中没有额外的命名空间,但是路由包含:

代码语言:javascript
复制
  <route xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
         id="xxxKeresE1_xslt_Route"
         streamCache="true">

如何在路由中消除额外的命名空间定义?特克斯角

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-03 13:06:39

由于您希望route元素位于不同的名称空间中,因此需要使用创建元素的名称空间,即更改

代码语言:javascript
复制
  <route id="{$service-name}_xslt_Route" streamCache="true">
         <from id="{$service-name}_from1" uri="cxf:bean:{$service-name}_LocalEndpoint?dataFormat=PAYLOAD"/>
         <convertBodyTo id="{$service-name}_convertBodyTo1" type="java.lang.String"/>
         <wireTap id="{$service-name}_wireTap1" uri="direct-vm:logRequest"/>
         <to id="{$service-name}_to2" uri="cxf:bean:{$service-name}_RemoteEndpoint?dataFormat=PAYLOAD"/>
         <convertBodyTo id="{$service-name}_convertBodyTo3" type="java.lang.String"/>
        <wireTap id="{$service-name}_wireTap3" uri="direct-vm:logResponse"/>
    </route>

代码语言:javascript
复制
  <route xmlns="http://camel.apache.org/schema/blueprint" id="{$service-name}_xslt_Route" streamCache="true">
         <from id="{$service-name}_from1" uri="cxf:bean:{$service-name}_LocalEndpoint?dataFormat=PAYLOAD"/>
         <convertBodyTo id="{$service-name}_convertBodyTo1" type="java.lang.String"/>
         <wireTap id="{$service-name}_wireTap1" uri="direct-vm:logRequest"/>
         <to id="{$service-name}_to2" uri="cxf:bean:{$service-name}_RemoteEndpoint?dataFormat=PAYLOAD"/>
         <convertBodyTo id="{$service-name}_convertBodyTo3" type="java.lang.String"/>
        <wireTap id="{$service-name}_wireTap3" uri="direct-vm:logResponse"/>
    </route>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50155594

复制
相关文章

相似问题

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