如何删除命名空间前缀,留下命名空间值(XSLT)? [英] How to remove namespace prefix leaving namespace value (XSLT)?

查看:31
本文介绍了如何删除命名空间前缀,留下命名空间值(XSLT)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全知道如何删除命名空间,但我需要做的只是删除特定的命名空间前缀,例如转换此文件(删除 xenc 前缀):

I know how to remove namespaces at all but what I need to do is only to remove specific namespace prefixes eg transform this file (removing xenc prefixes):

<?xml version="1.0" encoding="UTF-8"?>
<xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
        <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
    </xenc:EncryptedKey>
    <ds:X509Data>
        <ds:X509Certificate>AAA=</ds:X509Certificate>
    </ds:X509Data>
</ds:KeyInfo>

进入这个:

<?xml version="1.0" encoding="UTF-8"?>
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
        <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
    </EncryptedKey>
    <ds:X509Data>
        <ds:X509Certificate>AAA=</ds:X509Certificate>
    </ds:X509Data>
</ds:KeyInfo>

你能帮我如何使用 XSLT 来完成吗?

Can you help me how it could be done using XSLT?

推荐答案

与 nwellnhof 的解决方案几乎相同.但是在样式表中使用默认命名空间.添加:xmlns="http://www.w3.org/2001/04/xmlenc#".

Nearly the same solution as from nwellnhof. But make use of default namesepace in stylesheet. Add: xmlns="http://www.w3.org/2001/04/xmlenc#".

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
                xmlns="http://www.w3.org/2001/04/xmlenc#"  >
    <xsl:output indent="yes"/>

    <xsl:template match="xenc:*">
        <xsl:element name="{local-name()}" >
            <xsl:apply-templates select="@*|node()"/>
        </xsl:element>
    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>


</xsl:stylesheet>

这篇关于如何删除命名空间前缀,留下命名空间值(XSLT)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆