1

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>

into this:

<?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>

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

2 Answers 2

2

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>
Sign up to request clarification or add additional context in comments.

Comments

1

Try the following stylesheet. It contains the identity transform and a template to strip the namespace of xenc:* elements. Note that xenc:* attributes are not handled.

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">

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

<xsl:template match="xenc:*">
    <xsl:element name="{local-name()}" namespace="http://www.w3.org/2001/04/xmlenc#">
        <xsl:apply-templates select="node() | @*"/>
    </xsl:element>
</xsl:template>

</xsl:stylesheet>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.