0
votes

Using xslt 1.0 (BizTalk 2016) I'm looking for a generic way to select the namespace of any valid xml document

For example, I have the following xml document:

<?xml version="1.0" encoding="utf-8"?>
<PortfolioActivation xmlns="http://www.random.com/bo/request/portfolioactivation">
    <Portfolio>
        <ExternalId>PRT-00000450</ExternalId>
        <InternalId>c8b0239c-1e98-e911-a8b1-00224800449b</InternalId>
        <Version>8627558</Version>
        <Type>001</Type>
    </Portfolio>
</PortfolioActivation>

Given that the Root element value could be anything, what would be the xpath to select the value of the namespace i.e http://www.random.com/bo/request/portfolioactivation

I had hoped "/*/@xmlns" would work but it doesn't.

1

1 Answers

1
votes

The namespace of the outermost element can be found using namespace-uri(/*).

Alternatively, the default namespace that's in scope for the outermost element is /*/namespace::*[name()=''].

These aren't the same thing. Consider

<p:root xmlns="a.ns" xmlns:p="b.ns"/>

The first expression will give you "b.ns", the second will give you "a.ns". It's not clear from your question which you want.

Note that namespaces are not attributes in the XDM data model, so you never access them using the attribute axis. @xmlns will therefore never work.