newbie: XML and stylesheets

M

Michael Lund

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
 
J

Joris Gillis

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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput 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,
 
M

Michael Lund

Joris said:
Hi,

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top