Larissa Rodrigues
Larissa Rodrigues

Reputation: 1

How to force an empty namespace in a XML file using XSLT transformation

I have a XSLT transformation that converts a XML, and I need to have the following empty namespace in one tag:

<RPS xmlns="">

The header of the XML file is:

<?xml version="1.0" encoding="UTF-8"?>
<RPS>...</RPS>

The header of the XSLT is:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:g="http://www.g2ka.com.br" xmlns:g2ka="com.g2ka.nfse.offline.util.OffLineUtils" xmlns:util="com.g2ka.nfse.util.Util" exclude-result-prefixes="g g2ka util">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" standalone="yes" indent="yes"/>

What can I do to force the xmlns="" in the RPS tag? Thanks for your help.

Upvotes: 0

Views: 243

Answers (2)

Michael Kay
Michael Kay

Reputation: 163262

In general, the XSLT processor will decide what namespace declarations are needed. Your job is to create your elements with names in the correct namespace. If you create an RPS element in no namespace, the processor will output xmlns="" if that is necessary to cancel an outer namespace declaration, but it won't output it if it is redundant.

Upvotes: 0

michael.hor257k
michael.hor257k

Reputation: 116959

This cannot be done in XSLT. An empty namespace declaration on the root element is entirely redundant and will be removed (unless you're using the libxslt processor).

Upvotes: 1

Related Questions