473,324 Members | 2,535 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,324 software developers and data experts.

XSL question for a newbie

3
I am just learning XSL to read from XML. How to read this xml please? I just cannot make to work though it looks simple. Thanks a bunch.


<?xml version="1.0" encoding="ASCII"?>
<?xml-stylesheet href="paramspec.xsl" type="text/xsl" ?>
<lm:Component xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lm="http:///com.ti.ipmeta.ecore" name="mcasp" description="Multi-channel Audio Serial Port" ipstatus="Development" ipcategory="Logic" ipfunction="OtherCommunications" memory="true" configurable="true">
</lm:Component>
And this my XSL sheet below
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<xsl:template match="/">
<html>
<head>
<title>IP Meta Status</title>
</head>
<body>
<h2>Name :</h2>
<xsl:for-each select="Component/name">
<xsl:apply-templates select="name"/>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="name">
<div style="font-family:Verdana, Arial; font-size:18pt; font- weight:bold">
<xsl:value-of select="."/>
</div>
</xsl:template>
</xsl:stylesheet>
Sep 26 '08 #1
5 2080
Dormilich
8,658 Expert Mod 8TB
to put it in simple words: this is a case of overkill.

(you could go for latin-1 or utf-8 charset as well)
btw. you only have one element defined...

the xsl cannot access the xml document tree, because the xml's namespace is missing, "name" is an attribute not an element (and therefore there is only one).

this should get you started:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <xsl:stylesheet 
  3.     version="1.0" 
  4.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  5.     xmlns:xdb="http://xmlns.oracle.com/xdb" 
  6.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  7.     xmlns:xmi="http://www.omg.org/XMI" 
  8.     xmlns:lm="http:///com.ti.ipmeta.ecore">
  9.  
  10. <xsl:template match="/">
  11. <html>
  12. <head>
  13. <title>IP Meta Status</title>
  14. </head>
  15. <body>
  16. <h2>Name :</h2>
  17. <div style="font-family:Verdana, Arial; font-size:18pt; font- weight:bold">
  18. <xsl:value-of select="/lm:Component/@name"/>
  19. </div>
  20. </body>
  21. </html>
  22. </xsl:template>
  23.  
  24. </xsl:stylesheet>
regards
Sep 29 '08 #2
unimax
3
That works. Adding the namespace and other suggested changed resolved it. I got confused with attribute and element. Thanks.
Sep 29 '08 #3
Dormilich
8,658 Expert Mod 8TB
I'm glad I could help
Sep 29 '08 #4
unimax
3
Is there a way I could loop thro' each of the attributes instead of processing each one by their name? Thanks.
Sep 29 '08 #5
Dormilich
8,658 Expert Mod 8TB
yes. how exactly you do it depends on the wanted output
Expand|Select|Wrap|Line Numbers
  1. // you can copy attributes
  2.  <xsl:template match="node()">
  3.          <xsl:copy>
  4.                  <xsl:copy-of select="@*"/>
  5.           <xsl:apply-templates select="node()"/>
  6.          </xsl:copy>
  7.  </xsl:template>
  8.  
  9. // or get them in a for-each loop
  10. <xsl:for-each select="@*">
  11. // use your code here
  12.     <xsl:value-of select="."/>
  13. </xsl:for-each>
regards
Oct 13 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Philippe C. Martin | last post by:
Hi, Is there a program out there that would generate the C code to instantiate objects and call them: ex: miracle.exe -i mymodule.py -o module_internface.c ? I seem to recall a _yes_ to...
0
by: Twayne | last post by:
Twayne wrote: That's the verification I was looking for I think. There are times that doesn't seem to be so, but perhaps I'll looking at the wrong side of the tree in the wrong forest ... I...
5
by: Banibrata Dutta | last post by:
Hi, I've gone through the list of "language differences" between 2.3 / 2.4 & 2.5 of CPython. I've spend around 2 weeks now, learning v2.5 of CPython, and I consider myself still very very...
16
by: Raxit | last post by:
Hi, i was reading/learning some hello world program in python. I think its very simillar to Java/C++/C#. What's different (except syntax) ? what can i do easily with python which is not easy...
10
by: Peter Michaux | last post by:
On May 14, 8:55 pm, Prisoner at War <prisoner_at_...@yahoo.comwrote: Get it from the library. I cannot imagine needing to own an HTML book. There are plenty of good references on the web....
2
by: r_ahimsa_m | last post by:
Could you recommend me some free JavaScript validator? I was using JSlint but it reports nonsense errors. Please help. Thanks. /RAM/
6
by: raylopez99 | last post by:
Will ASP.NET 3.0 work under Visual Studio 2005? And what is a good newbie ASP.NET book? Subject: Will ASP.NET 3.0 work under Visual Studio 2005? And what is a good newbie ASP.NET book? My...
3
Lokean
by: Lokean | last post by:
Sorry for this newbie question, this is not my realm of expertese. I have searched google, tried several applications that claim they can do this, such as Mapforce, which I found confusing, to...
5
by: Dave | last post by:
I am new to Visual Web Developer 2005 Expres. I am using absolute positioning and every time I add a button control to my web form its width extends all the way to the edge of the page. IOW I...
5
by: SharkD | last post by:
Hi! I'm a total newbie when it comes to ASP (or any type of server-side programming). I want to start a project that does the following: 1. query Wikipedia for information regarding...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.