473,387 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 3368
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: qa4ever | last post by:
How long in number of characters can a XML attribute be maximum? E.g. <mystring>how many characters maximum can be here</mystring> If you answer something like; it can be as long as UTF-8 . Then...
3
by: schaf | last post by:
Hi ! I have a little question. With my XSL File I add additional XML-Tags to an existing XML-File. But I would like to use a xsl:variable for inserting a value into an additional xml-attribute. ...
0
by: kosaraju.puneeth | last post by:
I am using Xml schema based validation for XML files. * I have attributes of Required,optional and anyAttribute type. Now can i validate my XML file in such a way that under a particular...
4
by: smita | last post by:
Hi, I have an xml file as below <root> <table id =1> <user>abc</user> <age>25</age> </table> <table id = 2> <user>xyz</user>
4
by: John Lau | last post by:
Hello, In Asp, you can render a server side variable inside the quotes in an html element attribute. For example: <link rel="stylesheet" href="<%=SomeVariableName%>" type="text/css"> I'm...
2
by: alexs | last post by:
Chaps, I'm starting to play with db2 V9.1 and am writing a stored procedure to manage accounting records from oiur RADIUS server. I've got an XML aware table with an auto increment primary...
1
by: emma_middlebrook | last post by:
Hi Goal: trying to validate a string to see if it can be a valid XML attribute name and, if not, replace any of the invalid characters with an underscore (to fix it up). Is there anything in...
1
by: Ravi | last post by:
Hi, I want to use end line character('\n') in the XML Attribute like <message confirm=" This will kill your process . \n Are you sure to proceeed? "/> But in java xml processor, it is...
0
by: sowmyavsh | last post by:
Below is my asp.net code which should fetch the correct answer from the xml document. how can i store the xml attribute (i.e to an object or string)? it is throwing an error object reference not...
2
by: sqad | last post by:
<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib"> ....something </JiraJelly> Anyone know how to create this xml tag using the xsl:element? Having a problem with the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.