Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT: Confusion over adding attributes with xml:element and xml:attribute

Reply
Thread Tools

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

 
 
Jordan Willms
Guest
Posts: n/a
 
      11-08-2004
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"
xmlnssi="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
 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      11-08-2004
(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"
> xmlnssi="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
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      11-09-2004
In article < >,
Jordan Willms <> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
attributes ala java annotations or .Net attributes? Kyle Schmitt Ruby 3 07-24-2007 07:48 PM
class attributes & data attributes james_027 Python 2 06-20-2007 03:12 PM
WebControl.Attributes.Add and custom attributes P4trykx ASP .Net 2 01-31-2007 04:33 PM
Parse reserved attributes as normal attributes Max XML 1 09-22-2006 12:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57