XSLT: Confusion over adding attributes with xml:element and xml:attribute

Jordan Willms

Usenet Archive
Joined
Oct 27, 2004
Messages
2
Reaction score
0
Hi there.

I am working with lom metadata and I am a little confused with how to form the following xml element:

<lom xmlns="http://www.imsglobal.org/xsd/imsmd_v1p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd"/>

I have the following so far:

<xsl:element name="lom">
<xsl:attribute namespace="xmlns"
name="xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:attribute>

<xsl:apply-templates/>
</xsl:element>

but it creates some very strange results. Does anyone know how I could go about forming this tag? I know I could do it withou xsl:element, but I'd like to do everything by the books.

Any help would be greatly appretiated.

Cheers!

...jordan willms
 

David Carlisle

Usenet Archive
Joined
Jan 5, 2000
Messages
609
Reaction score
0
Hi there.

I am working with lom metadata and I am a little confused with how to form the following xml element:

<lom xmlns="http://www.imsglobal.org/xsd/imsmd_v1p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd"/>

I have the following so far:

<xsl:element name="lom">
<xsl:attribute namespace="xmlns"
name="xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:attribute>

<xsl:apply-templates/>
</xsl:element>

but it creates some very strange results.

actually you shouldn't get a result at all, it is a syntax error to try to generate an attribute with name xmlns. XML namespace declarations are not attributes as far as Xpath is concerned, they can't be generated with xsl:attribute, they don't show up if you select @*.

Just generate the attribute that you need (xsi:schemaLocation) any needed xml namespace declarations will be generated automatically.
Does anyone know how I could go
about forming this tag? I know I could do it withou xsl:element, but I'd like to do everything by the books.

Not sure what you mean by "by the books" I'd expect most xslt books to advise thatyou don't need to use xsl:attribute or xsl:element unless you need to generate the element or attribute names dynamically. The main idea of xslt is that the templates should look like a "template" for part of your result document, so it would b emore natural to just use the form you give at the top rather than using xsl:element.
Any help would be greatly appretiated.

Cheers!

..jordan willms

David
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
Jordan Willms said:
I know I could do it withou xsl:element, but I'd
like to do everything by the books.

By what book? There is no good reason to use xsl:element when you could use a literal result element. You're just making life unnecessarily complicated.

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,802
Members
249,594
Latest member
henrywalsh

Latest Threads

Top