1

I need to insert an element with xs:type inside it like an attribute, while transforming my xml file using an xslt.

The output needed is in the following format

<Region xs:type="tRegion"/>

But in xslt file it shows the compile time error "Namespace prefix 'xs' is not defined". But I don't want to define a namespace here. Instead add a colon.

Kindly suggest a solution for this issue.

Agnus
  • 17
  • 1
  • 8

2 Answers2

2

XSLT works on namespace well-formed XML (both for input and output) and is itself namespace well-formed XML so having an attribute name with a colon without declaring a namespace for the prefix before the colon is not possible because https://www.w3.org/TR/xml-names/#ns-qualnames mandates:

The Prefix provides the namespace prefix part of the qualified name, and MUST be associated with a namespace URI reference in a namespace declaration

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • +1 See also [Is a colon a legal first character in an XML tag name](https://stackoverflow.com/q/40445735/290085) – kjhughes Oct 12 '17 at 14:44
0

The output <Region xs:type="tRegion"/> can be obtained by adding the following definition for 'xs'

xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"

Thanks.

Agnus
  • 17
  • 1
  • 8
  • That, of course, is the right way to eliminate the error, but you should accept Martin's answer because it's correct given that you said you *don't want to define a namespace here. Instead add a colon.* – kjhughes Oct 13 '17 at 12:43