xsl-list
[Top] [All Lists]

RE: [xsl] Adding an element of a specific type

2006-10-18 23:32:53



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.

That's indeed what I meant.

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>

I didn't realise it was that simple. It does what I want. Thanks!
I do wonder however, why xsl:element does not have any means for doing
that.


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>


That didn't give me a version, but it gave me 'Tibco, Inc', which is
quite 
obvious, since I am working with Tibco BusinessWorks.

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.

I am sorry for that, but I don't think there is anything I can do about
it.

Regards,
Peter Hofman


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



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>