f



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
0
jpwillms (2)
11/8/2004 7:48:56 PM
comp.text.xml 8781 articles. 0 followers. Post Follow

2 Replies
703 Views

Similar Articles

[PageSpeed] 43

jpwillms@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
0
davidc5020 (601)
11/8/2004 9:47:26 PM
In article <bb08020c.0411081148.6b53f55a@posting.google.com>,
Jordan Willms <jpwillms@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
0
richard91 (3692)
11/9/2004 12:25:41 AM
Reply:

Similar Artilces:

Retrieving XML attribute using XML::XPath::Node::Attribute
Hi I am trying to retrieve an attribute of a particular node from my XML using "XML::XPath::Node::Attribute", but couldn't come across on how to successfully use it in my code. For example, if my xml is: <?xml version="1.0" ?> <data> <server_address port="40">10.0.0.1</server_address> </data> How do I go about fetching the "port" attribute from "server_address" element? Vikrant vikrant wrote: > > <?xml version="1.0" ?> > <data> > <server_address port="40&q...

get xml attribut from a xml
hi... i load some xml into my program but now need to do complex thing whit it, and cant figure out... in my xml i got plany items..... but i want to get all items which have gril on "ok" in the data content... is that possible and how ? need help <items itemno=3D"1234"> <name>kartofler</name> <data> <data content=3D"gril">ok</data> <data content=3D"ovn">280 grader</data> <data content=3D"kogning">30 min p=E5 plus</meta> </data> ...

web.xml / XML schema issue, why do some XML schema attributes disappear
Hi I'm trying to get my j2ee app to run on Jboss (version 3.2.3), but Jboss complains there are some missing attributes in the web-app element. The attributes are present in the XML file, but they seem to be removed by the parser, also when I view the file in a web browser. My XML below (I have cut out a lot of stuff for the purpose of this post) <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app xmlns="...

To XML or not to XML?
Ok, it has been a while since I've needed to make an involved web page. Coming back on the scene now is a bit confusing, what with all the cool stuff to use like XML, PHP, MySQL, etc... So here is my question. I'm in search of a good dynamic way to generate web pages which separates content from presentation. I am seeking to create a web site that, to put it succinctly, has a list of users and sets of information corresponding to each user. I am familiar with how to do this using PHP, MySQL, and regular old HTML. I maintain the user database in MySQL and dynamically present it and the information with PHP. This is very easy to do in terms of coding for it. But I'm wondering? Is it time for me to switch to the XML with XSL method instead? Everyone seems to be talking of XML as the end all be all. I've looked into it, and on the surface, I just can't tell if it's worth it. I don't really see the benefit. XML is just a "create your own HTML tags" and then figure out wtf to do with them orgy. Great, so I can write <dog>Spot</dog>. Whoop de do, that's useless to me unless I write a parser for it to display it in a user friendly way. And I shouldn't have to write a parser, there should be standardized ones for certain purposes. But wait, isn't that what HTML already is? A bunch of <dog>Spot</dog> (figuratively speaking) with the parsers having been written and mostly standardized between companies ages ago...

XML to XML
I have a gnucash file that I'm trying to transform into an identical XML file without the invoices. I've been at this for a while now. The gnucash file is in XML and the element I'm looking into is: <gnc:transaction> I want to ignore those that contain <slot:key>gncInvoice</slot:key> which is a child of slot which is a child of slots which is a child of transactions. Any help you're willing to provide would be greatly appreciated. Thanks. Classic application for XSLT. Start with the identity transformation, then add a template which matches the ones you want to treat specially and yields no output. From your description that would be match="gnc:transaction[transactions/slots/slot/slot:key='gncInvoice']" with the namespaces declared appropriately in the stylesheet. (That looks like a somewhat unlikely markup design to me, but since I haven't played with gnucash at all I'm taking your word for it.) -- () ASCII Ribbon Campaign | Joe Kesselman /\ Stamp out HTML e-mail! | System architexture and kinetic poetry Actually, from the Relax-NG schema for gnucash, it looks like it should be more like "gnc:transaction[trn:slots/slot/slot:key='gncInvoice']" with gnc:, trn:, and slot: all bound to the appropriate namespace URIs. The fact that some of their elements -- eg <slot> -- aren't in any namespace is probably left over from a pre-namespaces initial design, as is their now-brok...

XML or not XML?
I am developing a simple MySQL database editor, and am looking into creating an PHP/AJAX app as the GUI. A lot of this in new ground, and much more is dusting off things I haven't used in a while. My question though involves whether or nor to employ XML. I did some XML a few years back, but don't typically bother anymore. As I see it XML is great when I need to have an app with a standard data presentation that other developers can easily interface. I.E. like a bank statement that may feed a variety of applications developed by a variety of clients. However, if I am develo...

Problem to insert an XML-element by XSLT-converting from one XML-file into another XML-file
Hello, i convert one XML-document by using XSLT into another XML-document. First change all attributes to elements is no problem. Then i try to insert a new element into the new document by XSLT, but it doesn't work correctly :-( Example: The XML-source-document: <?xml version="1.0" encoding="UTF-8"?> <data creationTime="2006-05-31" creationNumber="1"> <set number="0001" info="test"/> <set number="0002" info="test"/> </data> The following XML-destination-document has to become (watch the new element "sets"): <?xml version="1.0" encoding="UTF-8"?> <data> <creationTime>2006-05-31</creationTime> <creationNumber>1</creationNumber> <sets> <set> <number>0001</number> <info>test</info> </set> <set> <number>0002</number> <info>test</info> </set> </sets> </data> Here is my XSLT-stylesheet-attempt: <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes" /> <xsl:template match="@*"> <xsl:element name="{name()}"> <xsl:value-of select="."/> </xsl:element> <xsl:if test="n...

embedding xml in xml as non-xml :)
Hi all, I have an application that logs in xml. Assume <xmlLog></xmlLog>. In this element the app logs anything it gets from foreign hosts. Now if the host sends xml data, the structure of the document changes. ie. <xmlLog><somTag></somTag></xmlLog>. This will cause problems with my log reader, because it assumes that <xmlLog/> contains non-xml data. My question is, is there a way to treat the data in the <xmlLog/> element as non xml data. Something I can do that would treat anything this element contains as a literal? Any help or suggestions would be greatly appreciated. Regards, Mark Mark Van Orman <mark@icsaccess.com> wrote: > Hi all, > > I have an application that logs in xml. > > Assume <xmlLog></xmlLog>. In this element the app logs > anything it gets from foreign hosts. Now if the host sends xml > data, the structure of the document changes. ie. > <xmlLog><somTag></somTag></xmlLog>. This will cause problems > with my log reader, because it assumes that <xmlLog/> contains > non-xml data. > > My question is, is there a way to treat the data in the > <xmlLog/> element as non xml data. Something I can do that > would treat anything this element contains as a literal? > > Any help or suggestions would be greatly ap...

XML Attribute to element
I am looking into using DBMS_XMLSAVE to put the contents of a larger XML file into a staging table where I can clean up some of the information and insert it into its final home... Problem is the Key is in an attribute and not an element so a genericized XML Looks like this: <Details> <Detail ID =1> <Col1>SomeData</Col1> <Col2></Col2> <Col3>Some other data</Col3> </Detail> ... </Details> I can't seem to find a good example of how to deal with this... DBMS_XMLSAVE complains that it can't f...

xml.dom.minidom losing the XML document type attribute
Hello group, when I read in a XML document with the xml.dom.minidom parser and write it out again, an attribute is lost: Input: <?xml version="1.0" encoding="utf-8" ?> [...] Output: <?xml version="1.0" ?> How can I fix this? Python is Python 3.0rc2 (r30rc2:67114, Nov 16 2008, 15:24:36) Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl�sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision�r Hans Joss aka HJP in de.sci.physik &l...

XML file-- XSLT transformation problem with attributes of root element
I'm applying a simple XSLT style sheet to an XML file. The style sheet is: http://piru.alexandria.ucsb.edu/~rnott/MetadataMapping/access-report.xsl The XML file is here: http://piru.alexandria.ucsb.edu/~rnott/MetadataMapping/dlese-adn.xml This works fine as long as the root element of the XML file is plain <itemRecord>, like this: <?xml version="1.0" ?> <itemRecord> <general> <title>Geology Fieldnotes</title> .... (and so on) The problem is that in my real-world application the element <itemRecord> needs to have attributes like this: <itemRecord xmlns="http://adn.dlese.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://adn.dlese.org http://www.dlese.org/Metadata/adn-item/0.6.50/record.xsd"> And whith this latter form of <itemRecord... the XSLT transformation no longer matches anything (There are no errors, however, just no output). Why is that? Thanks for any help and advice. Wolfgang, Santa Barbara, CA In article <7929f723.0404061420.3daa9689@posting.google.com>, Wolfgang <mot12345@alexandria.ucsb.edu> wrote: [...] % The problem is that in my real-world application the element % <itemRecord> needs to have attributes % like this: % % <itemRecord xmlns="http://adn.dlese.org" % xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" % xsi:schemaLocation=&qu...

XML file-- XSLT transformation problem with attributes of root element #2
I'm applying a simple XSLT style sheet to an XML file. The style sheet is: http://piru.alexandria.ucsb.edu/~rnott/MetadataMapping/access-report.xsl The XML file is here: http://piru.alexandria.ucsb.edu/~rnott/MetadataMapping/dlese-adn.xml This works fine as long as the root element of the XML file is plain <itemRecord>, like this: <?xml version="1.0" ?> <itemRecord> <general> <title>Geology Fieldnotes</title> .... (and so on) The problem is that in my real-world application the element <itemRecord> needs to have attributes like this: <itemRecord xmlns="http://adn.dlese.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://adn.dlese.org http://www.dlese.org/Metadata/adn-item/0.6.50/record.xsd"> And whith this latter form of <itemRecord... the XSLT transformation no longer matches anything (There are no errors, however, just no output). Why is that? Thanks for any help and advice. Wolfgang, Santa Barbara, CA ...

XSLT: Passing the whole source XML through to the result XML with only some elements altered
Hi all. I've read Michael Kay's "XSLT" book, and used XSLT successfully as an HTML template system at our company (using basically the "fill-in-the-blanks" pattern of XSLT use: A template matching the root node, containing the HTML page, with lots of <xsl:value-of.../>, etc.). However, I've recently got a task that got me stumped, and I don't know if I'm missing something obvious, but quite frankly, I don't know where in the sea of XSLT-information to start looking (although I'll continue with that after having posted this), that I kindly ask for some guidance from you. The problem is this: We have a quite complex source XML document like this (each element may have several attributes): <root> <element1 ...> <element2...> <element3...> <element4...> ... </element4> </element3> ..=2E. (lots more elements and attributes) We'd like to basically copy this to the result XML, as it is, but change a few of the elements, like this: <root> <element1 ...> <element2...> <element3...> <element4...> <new_element...> <another_new..../> </new_element> </element4> </element3> ..=2E. (lots more elements and attributes) Is there a way to write an XSLT template that does this (passes the source XML unchanged, and changing ...

perl, XML::LibXML: encoding problems while changing attributes on an XML string
Hello, I'm parsing a chunk of XML code and would like to add attribute values to individual tags if these are lacking. This is with perl 5.8.6, libxml2 2.6.17, XML::LibXML 1.58. Basically, I have the parser add the attribute values to the respective nodes and then use the toString method of XML::LibXML::Document to write the modified text to a scalar. Both the original and the modified text evaluate properly as utf8, but the modified text doesn't print properly on the console, nor does it get entered as utf8 into a MySQL database. I don't really understand what's going on, and on what level the error(s) could be located (console encoding, perl encoding, XML encoding), and would appreciate any help I can get ... Here's the code: ------------------------------------------------ #!/usr/bin/perl use strict; use XML::LibXML; use Encode 'decode_utf8'; use vars qw ($parser $p); $parser =3D XML::LibXML->new(); my $version =3D XML::LibXML::LIBXML_DOTTED_VERSION; print "libxml2 $version\n-------------\nXML::LibXML $XML::LibXML::VERSION\n-------------------\n"; $p->{text} =3D qq| <p> <q who=3D"Blabla">pram=C4=81=E1=B9=87av=C4=81rttikasvav=E1=B9=9Btti=E1=B9= =AD=C4=ABk=C4=81</q> And this is some further text.<br/>And even more text.<br/>And more. <q who=3D"Blabla2">The second quotation!</q>. pram=C4=81=E1=B9=87av=C4=81rttikasvav=E1=B9=9Btti=E1=B9=AD=C4=ABk=C4=81. </p>...

XML::XSLT not recognizing attributes
The module XML::XSLT seems not to recognize attributes. According to what I read about patterns[1], this bit of XSLT should set the string "FUBAR" before each and every h3 element where the attribute class contains the value "subtitle": <xsl:template match='h3[@class="subtitle"]'>FUBAR <xsl:apply-templates/> </xsl:template> It doesn't seem to do that. However, it works without the attribute: <xsl:template match='h3'>FUBAR <xsl:apply-templates/> </xsl:template> What am I missing or doing wro...

Adding Attributes to all XML Nodes
Howdy, I have an PHP page that edits XML files. I want ADD a new *id* attribute to all nodes on the page that do not have it all ready. Then i want to delete all of the values of *id* and set them as an incremental 1-x values down the page. This is the current code i am using to edit specific nodes. Im trying to use DOM, but it doesn't have to be. I just need it to work. [code] <?php $content = $_POST['content']; $id = $_POST['id']; $node = $_POST['node']; $explode = explode("_",$node); $dom=new DOMDocument(); $dom->load('sample.xml'); $dom->formatOutput = true; //echo $dom->saveXML(); // show before file $allnodes = $dom->getElementsByTagName($explode[0]); foreach ($allnodes as $nodes) { if ($nodes->nodeName==$explode[0] and $nodes->getAttribute('id')== $id) { // $nodes->setAttribute($explode[1],$content); } } $dom->save('sample.xml'); ?> [/code] This is the XML file im working with. **NOTE** the missing *id* attributes of the 2nd *child01* node. [code] <?xml version="1.0" encoding="utf-8"?> <parent option01="other info" option02="other info" id="1"> <child01 option01="child01 option01" option02="child01 option02" id="2"> <child02 option01="child02 option01" option02="child02 option02" id="3"> <text option...

XML to XML Transformation
I was thrust into XML about 2 weeks ago and don't know much yet. From another department in the corp I am receiving an XML file which concatenates nodes all on one line i.e. <car><make>ford</make><color>red</color><year>2001</year></car><car><make><mb> etc. etc. etc. Some lines are over 300 characters long. I need to translate this spagetti XML into something which is humanly readable. I probably need to use XSL however I'm not sure what I need to do. Any help will be much appreciated. "Will" <william.cook@kla-tencor.com> wrote in message news:8506d1f6.0310311244.49a0856c@posting.google.com... > I was thrust into XML about 2 weeks ago and don't know much yet. From > another department in the corp I am receiving an XML file which > concatenates nodes all on one line i.e. > <car><make>ford</make><color>red</color><year>2001</year></car><car><make><m b> > etc. etc. etc. Some lines are over 300 characters long. I need to > translate this spagetti XML into something which is humanly readable. View the xml file using IE or Mozilla -- they provide an appealing, aesthetic looking layout with collapse/expanding of contents of elements. > I probably need to use XSL however I'm not sure what I need to do. If you decide to use XSLT (if, because the first approach above is really what one needs...

Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser)
Hello Usenet. I'm subject to some confusion with XML and UTF8. I'm working with XML-Simple and I try to decode some XML with with german umlauts (ISO-8859-1). The first XML line declared the encoding correct (see code below). But I'm getting different results using XML-Simple with the default XML parser named XML::Sax and a second parser named XML::Parser. The following code tries to decode the mini XML file and prints the UTF8 flags of the resulting strings. Can someone run this code on his machine and post the results? Thanks. The results on my machine are this: ���ä...

xml from 2 xml
Hi to everybody, would I like to create a consequential xml from the elaboration of two files xml using xslt, but is it possible to give in input to a trasform 2 files xml? thanks for the possible answers I have already found from me the answer: the function document('file2.xml') matatu ha scritto: > Hi to everybody, > > would I like to create a consequential xml from the elaboration of two > files xml using xslt, but is it possible to give in input to a trasform > 2 files xml? > > thanks for the possible answers ...

XML/XSL newb q: can I ever select or refer to xml attribute values?
I mean, with XSL functions such as SELECT can I only refer to XML element values or can I somehow also refer to XML attribute values? Is there any way to refer to XML content based on attribute values? Or is it a parsed data only thing? BTW, new to XML; sorry if this is a dumb question. I just haven't seen this explicitly stated anywhere (though by experience it doesn't seem to work). In article <f50415a8.0404291400.17de8650@posting.google.com>, 5tein <stein@cc.usu.edu> wrote: % I mean, with XSL functions such as SELECT can I only refer to XML % element values or can I somehow also refer to XML attribute values? I hate it when people as questions in the subject line, then don't repeat them in the body of the message. Select isn't a function -- rather it's an attribute of several elements. This attribute always contains an xpath expression, so you can refer to anything xpath can refer to. As it happens, you can refer to attributes. It's worth reading an introduction to xpath, but you can do something like <xsl:value-of select='@x'/> to get at the value of attribute x of the current node. -- Patrick TJ McPhee East York Canada ptjm@interlog.com ...

[XML] Is there an XML group?
Hi, I've typed an XML source which calls a CSS source, the result should be a page displayed in IE6, instead I see the XML source. That's pretty logical since there a no XHTML tags for IE6 to interpret. I'm looking for a discussion group like'comp.lang.xml' but I can't find one. Please help me. The first task is to see the Blue Jay. universalbitmapper wrote: > I'm looking for a discussion group like'comp.lang.xml' but I can't find > one. There's a comp.text.xml, which might be what you're looking for. Note that I don't read it,...

XML to XML conversion
Hello, I vageuly remember a standard that allowed for an XML document using one tag vocabulary to be translated to a diffirent XML document using a diffirent tag vocabulary using the information provided in a kind of dictionary XML pointed to in an URL present in the original XML file. I am very interested in trying it out for various applications, but I can't find anything on the internet about it, since I don't remember it's name, only the general appearance. Can anyone help me with this? What I remember, approximately: The idea is that you have one XML file, in which the namespace is defined in the standard way, using an URI. The URI, however, is pointing to an online XML file. For example: <x xmlns:abc="http://www.server.org/dictionary.xml"> <abc:one>orange</abc:one> </x> This dictionary.xml then contains, for example: <root> <one> <format1>1</format1> <format2>uno</format2> <format3>ena</format3> <format4>ein</format4> </one> </root> So a program wishing to convert the original XML to, say format2, would end up with the following XML: <x> <uno>orange</uno> </x> What I remember is that this dictionary trick was mainly used to allow diffirent software to be able to interpret the same XML file, without all of the software needing to be programmed for the same tag vocabulary. The program w...

Transform XML to XML using XSLT
hello all, seems like a simple issue, but having tried several approaches with no success I am posting this question, I have a XML in one format, I want to now convert into another XML format using XSLT. FirstType.XML: (In this XML the States sub elements appear within USA element) ------------------------------------------------ <?xml version="1.0" encoding="utf-8"?> <ROOT> <Country> <USA> <State> <City1>6000</City1> <City2>100</City2> <City3> </City3> </State> <State> <City1>1000</City1> <City2>10</City2> <City3>2</City3> </State> </USA> </Country> </ROOT> ------------------------------------------------ DestinationXML: (I want the above XML to appear this way, note the element <Type> is something I want to add - and is not in the originial XML) ------------------------------------------------ <?xml version="1.0" encoding="utf-8"?> <Region> <Area> <Type> Original </Type> <City1>6000</City1> <City2>100</City2> </Area> <Area> <Type> Original </Type> <City1>1000</City1> <City2>10</City2> </Area> &l...

XSLT problem: how to transfer from XML to XML?
I would like to transfer my XML file into another XML which has a struct like this: <catalog> <media> <cd>myCD</cd> </media> </catalog> However using my XSLT I could only get: <catalog>myCD</catalog> Can you please point out where my problem is? Thanks very much in advance. Leo <xsl:template name="catalog"> <xsl:call-template name="mytemplate"> <xsl:with-param name="ename">catalog</xsl:with-param> <xsl:with-param name="evalue"> <xsl:choose> <xsl:when test="/myxpath"> <xsl:call-template name="mytemplate"> <xsl:with-param name="ename">media</xsl:with-param> <xsl:with-param name="evalue"> <xsl:call-template name="mytemplate"> <xsl:with-param name="ename">cd</xsl:with-param> <xsl:with-param name="evalue" select="/myxpath1"/> </xsl:call-template> </xsl:with-param> </xsl:call-template> </xsl:when> ... <xsl:template name="mytemplate"> <xsl:param name="etext"/> <xsl:param name="ename"/> <xsl:param name="evalue"/> <xsl:if test="($evalue!='') and ($evalue!='none')"> <xsl:element name="{$ename}"> <xsl:if tes...

Web resources about - XSLT: Confusion over adding attributes with xml:element and xml:attribute - comp.text.xml

Resources last updated: 3/14/2016 12:19:13 AM