Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > newbie: XML and stylesheets

Reply
Thread Tools

newbie: XML and stylesheets

 
 
Michael Lund
Guest
Posts: n/a
 
      12-24-2004
Hi,

I have this XML.

<stuff>
<class name="class a" superclass="">
<field name="field a" type="int">a is an integer</field>
<class>
<class name="class aa" superclass="a">
<field name="field aa" type="string">aa is a string</field>
<class>
<class name="class ab" superclass="ab">
<field name="field b" type="stuff">b is something else</field>
<class>
</stuff>


I need a stylesheet that can give med the output:

Class a:
field a - integer - a is an integer

Class aa:
field a - integer - a is an integer
field aa - string - aa is a string

Class ab
field a - integer - a is an integer
field b - stuff - b is something else


But I haven't got the slightest idea how do this
NB: there is no guarantee that "class a" occur before the other classes
in my XML.

Can you help get me startet?

thanks and merry christmas,
Michael
 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      12-24-2004
Hi,

> I have this XML.
>
> I need a stylesheet that can give med the output:
> But I haven't got the slightest idea how do this
> NB: there is no guarantee that "class a" occur before the other classes
> in my XML.
>
> Can you help get me startet?


This stylesheet will output what you gave as an example:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

<xslutput method="text"/>
<xsl:key name="field" match="field" use="substring-after(@name, 'field ')"/>

<xsl:template match="stuff">
<xsl:apply-templates select="class">
<xsl:sort select="substring-after(@name, 'class ')"/>
</xsl:apply-templates>
</xsl:template>


<xsl:template match="class">
<xsl:value-of select="@name"/>:
<xsl:apply-templates select="key('field','a')|*">
<xsl:sort select="substring-after(@name, 'field ')"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="field">
<xsl:text> </xsl:text><xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</xsl:template>

</xsl:stylesheet>

The stylesheet will most likely not work in another situation because I don't really understand how it should be determined what fields have to be printed for a class. Does it perhaps depend on the 'superclass' attribute? I'm not sure... Maybe you could give more information? In any case you might use this stylesheet to get an idea how it would work.

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Happy X-mas
 
Reply With Quote
 
 
 
 
Michael Lund
Guest
Posts: n/a
 
      12-25-2004
Joris Gillis wrote:
> Hi,
>
>> I have this XML.
>>
>> I need a stylesheet that can give med the output:
>> But I haven't got the slightest idea how do this
>> NB: there is no guarantee that "class a" occur before the other classes
>> in my XML.
>>
>> Can you help get me startet?

> This stylesheet will output what you gave as an example:


Thanks for your help.
I will look at this as soon as all the christmas family stuff is over

> The stylesheet will most likely not work in another situation because I
> don't really understand how it should be determined what fields have to
> be printed for a class. Does it perhaps depend on the 'superclass'
> attribute? I'm not sure... Maybe you could give more information? In any
> case you might use this stylesheet to get an idea how it would work.



What I want is this: For a given class print the class name. After that
print all the fields in the class starting with all the fields from the
super class (and before that the fields from the super classes super class).

thanks,
Michael
 
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
multiple xml stylesheets Kevin XML 0 03-05-2008 04:12 PM
loading a single xml file with different stylesheets jim XML 1 07-24-2007 04:36 AM
Properties, Styles and StyleSheets for a web control JezB ASP .Net 2 05-17-2004 08:22 AM
SmartNavigation, Stylesheets and Frames =?Utf-8?B?U2xlZXB5?= ASP .Net 2 05-04-2004 01:16 AM
using multiple stylesheets with 1 xml file steve XML 4 12-03-2003 10:03 AM



Advertisments