469,358 Members | 1,585 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

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

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
Jul 20 '05 #1
2 3211
jp******@sfu.ca (Jordan Willms) writes:
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
Jul 20 '05 #2
In article <bb**************************@posting.google.com >,
Jordan Willms <jp******@sfu.ca> wrote:
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
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by qa4ever | last post: by
3 posts views Thread by schaf | last post: by
4 posts views Thread by smita | last post: by
1 post views Thread by Ravi | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.