xml


How to add namespace element using XSLT


I have a problem.
Element Response must be without namespaces (They are defined root element).
Input XSLT:
<xsl:stylesheet
xpath-default-namespace="http://www.iata.org/IATA/EDIST"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:h="http://www.iata.org/IATA/EDIST"
version="1.0"
>
<xsl:template match="h:Response[not(h:OrderViewProcessing)]">
<Response xmlns="http://www.iata.org/IATA/EDIST">
<OrderViewProcessing>
<MarketingMessages>
<MarketingMessage>
<Text>
Error text
</Text>
</MarketingMessage>
</MarketingMessages>
</OrderViewProcessing>
<xsl:apply-templates/>
</Response>
</xsl:template>
</xsl:stylesheet>
Output XML:
<Response xmlns:h="http://www.iata.org/IATA/EDIST"
namespace="http://www.iata.org/IATA/EDIST">
<OrderViewProcessing>
<MarketingMessages>
<MarketingMessage>
<Text>
Error Text
</Text>
</MarketingMessage>
</MarketingMessages>
</OrderViewProcessing>
</Response>
I need like XML:
<Response>
<OrderViewProcessing>
<MarketingMessages>
<MarketingMessage>
<Text>
Error Text
</Text>
</MarketingMessage>
</MarketingMessages>
</OrderViewProcessing>
</Response>
If you remove xmlns = "http://www.iata.org/IATA/EDIST" in XSLT, then xmlns = "" in XML becomes empty.
Update
This problem solved in this way:
<xsl:template match="h:Response[not(h:OrderViewProcessing)]">
<xsl:element name="Response" namespace="http://www.iata.org/IATA/EDIST">
<xsl:element name="OrderViewProcessing" namespace="http://www.iata.org/IATA/EDIST">
<xsl:element name="MarketingMessages" namespace="http://www.iata.org/IATA/EDIST">
<xsl:element name="MarketingMessage" namespace="http://www.iata.org/IATA/EDIST">
<xsl:element name="Text" namespace="http://www.iata.org/IATA/EDIST">
Error text
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Probably, solution must be better.
You're using xpath-default-namespace and version="1.0", which looks inconsistent, since this attribute is defined only in XSLT 2.0. You always need to tell us which version of XSLT you are using.
You're explicitly creating the Response element in namespace "http://www.iata.org/IATA/EDIST" though you say you want it to be in no namespace. Why are you doing this?
You say that your output has the attribute namespace="http://www.iata.org/IATA/EDIST" but there is nothing in your XSLT that could conceivably generate this attribute. I think this must have been from some experimental variation of your XSLT.
In general, if you need to declare namespaces in the stylesheet and don't want them copied into the output, you should specify exclude-result-prefixes="#all" on the xsl:stylesheet element. But I think there's a little bit more going on here that you haven't explained clearly.

Related Links

Xpath: selecting nodes that have a certain child node
Excel VBA import xml file
How to convert this into dtd attribute?
Cannot run installer script in Magento (1.8.x)
Icons element with xml-file
Reading XML database according to schema
Bad character escaping when parsing xml from oracle clob
Saxon XSLT - Doctype preserve from input
xml specific tag transformation using xslt
XML child item search with Powershell
How to run a sub on Excel Ribbon action?
Use two xsd schemas in visual studio 2012
urlset tag issue when creating sitemap.xml using classic ASP
Xpath How to get one element using another element text value
Processing XML document
Group and Sub group element nodes of same row with predefined file format

Categories

HOME
windows
uml
linkedin
apache-flink
numbers
saml-2.0
oracle-apex-5
hugo
opengl-3
nstableheaderview
discrete-mathematics
bing-maps
categorical-data
openpyxl
ipmitool
openbugs
intercom
favicon
flatpak
libusb
alpacajs
package.json
fileserver
jersey-1.0
identity-management
jmp
sse
gmm
symbols
question2answer
event-store
tiki-wiki
itunes
beautifier
surveymonkey
licensing
android-maps
progress-bar
uitapgesturerecognizer
mockjax
cognos-bi
database-comparison
fstream
autolisp
papaparse
sammy.js
keras-layer
getpixel
least-squares
imx6
engine.io
raft
filesystemwatcher
azure-arm
drupal-theming
dynamic-linq
builder
identification
static-cast
css-transforms
universal-analytics
restore
materialized-path-pattern
stripe-connect
i386
embedding
kango-framework
spreadjs
libav
assertion
doctype
delayed-execution
iso-prolog
human-computer-interface
tweenlite
encryption-asymmetric
trdion2011
gnumeric
memset
radiant
vsx
fpdi
dsym
conditionaltagsupport
away3d
inappsettingskit
cmmi
flex++
merb
cardreader
android-sdk-2.3
xcode3.2
veracity
failing-tests
jquery-address
saxparseexception
htdocs
mysql-error-1205
xui
fdf
linfu-dynamicproxy
soappy
leader

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile