newbie: XML and stylesheets

Discussion in 'XML' started by Michael Lund, Dec 24, 2004.

  1. Michael Lund

    Michael Lund Guest

    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
     
    Michael Lund, Dec 24, 2004
    #1
    1. Advertising

  2. Michael Lund

    Joris Gillis Guest

    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,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Happy X-mas
     
    Joris Gillis, Dec 24, 2004
    #2
    1. Advertising

  3. Michael Lund

    Michael Lund Guest

    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
     
    Michael Lund, Dec 25, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2xlZXB5?=

    SmartNavigation, Stylesheets and Frames

    =?Utf-8?B?U2xlZXB5?=, May 3, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,452
    =?Utf-8?B?U2xlZXB5?=
    May 4, 2004
  2. JezB
    Replies:
    2
    Views:
    412
  3. steve
    Replies:
    4
    Views:
    1,097
    Baldo
    Dec 3, 2003
  4. jim
    Replies:
    1
    Views:
    765
    Wizfrog
    Jul 24, 2007
  5. Kevin

    multiple xml stylesheets

    Kevin, Mar 5, 2008, in forum: XML
    Replies:
    0
    Views:
    407
    Kevin
    Mar 5, 2008
Loading...

Share This Page