首页 > 解决方案 > XSLT 生成不需要的名称空间

问题描述

我有一个这样的xml:

<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">
<cm:property-placeholder persistent-id="pot_kodtar_service" update-strategy="reload"/>
...
<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>

我想在最后一个条目之后附加一个新元素。如果我发现最后一个没有命名空间的元素是这样的:

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

我在输出文档中得到额外的命名空间,如下所示:

               <entry key="xxxValtozasE1" value="xxxValtozasE1Role"/> <!-- that is last existing element-->
        <entry xmlns=""
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               key="xxxElemKeresE1"
               value="xxxElemKeresE1Role"/> <!-- that is newly added element with unwanted namespaces-->

插入的条目包含额外的 xmlns:="" 和 xmlns:xsd="..." 定义。如何消除这些额外的命名空间定义?

谢谢扎梅克

标签: xmlxslt

解决方案


在样式表的或根元素上添加xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"和。第一个建议应该将结果元素放在输出命名空间中,第二个建议应该避免输出我想你已经在样式表中声明的输出。exclude-result-prefixes="xsd"xsl:stylesheetxsl:transformxmlns:xsd


推荐阅读