[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Adding an element of a specific type

Subject: RE: Adding an element of a specific type
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 18 Oct 2006 15:44:27 +0100
RE:  Adding an element of a specific type
> How do I add an element of a specific type to the output.

Your real question is, how do I add:

(a) an xsi:type attribute whose value is a QName, together with
(b) a namespace node that binds the prefix used in that QName.

If the prefix used in the QName is the same as the prefix used in the
containing element, which is the case in your example, then I would expect
the namespace to be declared automatically, so you shouldn't need to do
anything special. Perhaps you over-simplified the example? What was the
actual XML output?

If the namespace is different, then it's still quite easy so long as you
know the namespace in advance. Just use a literal result element instead of
xsl:element. That is, change

<xsl:element name="ns1:Q">
        <xsl:attribute name="xsi:type">ns2:Q_Type</xsl:attribute>
        <xsl:apply-templates select="ns1:C" >
</xsl:element>

to

<ns1:Q xsi:type="ns2:Q_Type" xmlns:ns2="some-namespace">
  <xsl:apply-templates select="ns1:C" >
</xs1:Q>

That's because literal result elements copy namespaces from the stylesheet,
while xsl:element doesn't.

> (sorry, but I am not sure which processor I have, since it is 
> embedded in an existing application)

It's a good idea to find out. Use

<xsl:comment>XSLT Processor: <xsl:value-of
select="system-property('xsl:vendor')"/></xsl:comment>

> This e-mail and any attachment is for authorised use by the 
> intended recipient(s) only. It may contain proprietary 
> material

Please tell your lawyers to stop adding such daft nonsense to your emails,
it brings their profession and your employers into disrepute.

Michael Kay
http://www.saxonica.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.