XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 5th, 2004, 07:25 AM
Aphex3k Aphex3k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 8 Aphex3k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Problems transforming XML with XSD using XSL

Ok, first I wan't to try to unconfuse those wondering about the headline...

IM' working with XML for 2 weeks now and I'm exited by its possibilities. I know waht the diffrence is bitween XSD and XSL but i didn't knew how to make the topic more precise.

I started to create and XSD suitable for all the XML files i would work with. After creating some example XML and sucessfully validating them against the schema I wanted to make the next step. I wrote some XSL. That was where my Problem begun.

I finished the XSL and wanted my XML to be transformed with it. When I comment the line in the XML that makes use of the XSD the XSL works perfectly.
When this line is uncommented the same XSL does not work anymore.

I'm checking the XML->XSL with the help of Mozilla Firefox (0.9.3) . It might be good to know.

To mak it more clear, hears some code example:
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="myschema.xsl" ?>

<MYschema
   xmlns="<URI>"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="<URI> myschema.xsd"
>...
Using this header i can check the XML against the XSD sucessfully.
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="myschema.xsl" ?>

<MYschema>...

Using this header i can transform the XML with the XSL.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>

<h2>attributeTypes</h2>
<ul>
<xsl:for-each select="attributetype">
   <li><xsl:value-of select="name" /> (<xsl:value-of select="oid" />)</li>
</xsl:for-each>
</ul>

<h2>objectClasses</h2>
<ul>
<xsl:for-each select="objectclass">
   <li><xsl:value-of select="name" /> (<xsl:value-of select="oid" />)</li>
</xsl:for-each>
</ul>

</body>
</html>
</xsl:template>
</xsl:stylesheet>

The above is only a simple try of XSL. As i said, when there is no referencing lines to the XSD it works. Whe the line are in, it seems like the xsl:for-each="node" is not triggered anymore.

So my final question:
What's the why to write a XSL thats processable with a XML that has lines oubt XSD in it?

Thanks in Advance!

Reply With Quote
  #2  
Old August 9th, 2004, 05:40 AM
Aphex3k Aphex3k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 8 Aphex3k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question

Could somebody please post at least a suggestion? This is really bugging me I still found no solution...

Reply With Quote
  #3  
Old August 11th, 2004, 12:16 PM
kid23 kid23 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 62 kid23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Ok, I'm going to reply in this post..

First things first. I think you're making a big confusion between what to expect from the different technologies, and how to work with them.

To explain it briefly, your XML file is the file that contains the data, and only the data. Since XML allows you to format your data without any constraint, it might be a good idea to set rules about the data themselves, especially if you intend to share these data with third parties.

There are two ways of doing it, XSD or DTD.

Then comes the problem of presenting your data to the outside world, this can be done by telling the browser how to do it. XSL files allow you to do that.

Since you're new to XML, XSL & XSD, I'd advise you to work differently:

- Build your XML file, with only data in it
- Add a reference to XSL into your XML file
- Build the XSL transformation rules, and don't stop until you get exactly what you want.
- Then, and only then, work on the data validation issue, by using XSD or DTD

Back to your issue.. from the data I saw in the other post, and the XSL in this one, I'd say that you have to work a bit differently again. It seems to me that you have misunderstood the concept of templates (no offense, it's just an impression), so I'm going to explain again here:

When you write a template like this one:

<xsl:template match="AnyNodeName">
...
</xsl:template>

It means to the browser : "Anytime you encounter a node named AnyNodeName into the XML file, replace it with the content of this template"

The cool thing about this is that if you write multiple templates to process XML tags, you can have several small blocks of code that will nest into one another automatically. If you've ever done any structured programming or scripting, this can be seen as creating functions.

In your case, you should have a main template that handles the root element (schema), and two others for attributetype & objectclass:

Code:
<xsl:template match="schema">
<html>
<body>

<h2>attributeTypes</h2>
<ul>
  <xsl:apply-templates select="attributetype" />
</ul>

<h2>objectClasses</h2>
<ul>
  <xsl:apply-templates select="objectclass" />
</ul>
</body>
</html>
</xsl:template>

<xsl:template match="attributetype">
  <li><xsl:value-of select="name" /></li>
</xsl:template>

<xsl:template match="objectclass">
  <li><xsl:value-of select="name" /></li>
</xsl:template>


One of the things I tend to avoid (although some might contradict me) is to create only one main template with match="/" for the root element. By definition, in XML, the root element may only appear once, so if you're writing an XSL file only for this type of doc, why not using the element name into the match="".

From what I see, your reference to XSD into XML is right.

I hope I haven't forgotten anything, let me know if this works or not

Grtz

Reply With Quote
  #4  
Old August 13th, 2004, 08:37 AM
Aphex3k Aphex3k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 8 Aphex3k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for your reply. I'll try some of your guess.
IMHO i allready tried most of your suggestions but i think i will redo them again. Maybe i've overseen something. If sucessfull, i will post.

Reply With Quote
  #5  
Old August 13th, 2004, 09:39 AM
kid23 kid23 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 62 kid23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
There's one thing I had overlooked in your post.. you're using mozilla firefox, and to be honest, I've faced transformation issues when I was working on non IE browsers (my pages were tested by friends on mozilla and firefox)... but I admit that my pages are rather complex (built out of several files).

I still haven't taken the time to work on cross-browser compatibility, but if all else fails, try your page with IE6, at least you'll know if the issues you're facing are browser related.

Reply With Quote
  #6  
Old August 16th, 2004, 07:46 AM
Aphex3k Aphex3k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 8 Aphex3k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I managed to get IE 6 running in Wine. But the outpu is still the same. I stopped working with XML for now. It is of not real use yet and as this problem is still bugging me i've got alot other usefull stuff to work with.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Problems transforming XML with XSD using XSL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT