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

J

Jordan Willms

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
 
D

David Carlisle

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
 
R

Richard Tobin

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
473,997
Messages
2,570,241
Members
46,833
Latest member
BettyeMacf

Latest Threads

Top