need help from xsl guru

Discussion in 'XML' started by eric, Oct 28, 2004.

  1. eric

    eric Guest

    Hi,
    I write an xml file structure and I would like to write an xsl file for it.
    Can someone give me some help??
    thank you.

    Eric

    <parents>

    <parent>
    <name> p1 </name>
    <id>1000</id>

    <child>
    <name> c1 </name>
    <id>1001</id>
    </child>

    <child>
    <name> c2 </name>
    <id>1002</id>
    </child>
    </parent>


    <parent>
    <name> p2 </name>
    <id>2000</id>

    <child>
    <name> c3 </name>
    <id>2001</id>
    </child>
    </parent>

    <parent>
    <name> p3 </name>
    <id>3000</id>
    </parent>

    </parents>
     
    eric, Oct 28, 2004
    #1
    1. Advertising

  2. eric

    Guest

    > I write an xml file structure and I would like to write an xsl file
    for it.
    > Can someone give me some help??


    An XSL to do what? format? transform? sort? filter?

    Try http://www.altova.com they have GUI based WYSIWYM (What You See Is
    What You Mean) editors that can help you create XSLTs
    In Peace,
    Saqib Ali
    http://validate.sf.net
     
    , Oct 28, 2004
    #2
    1. Advertising

  3. eric

    eric zhou Guest

    I would like to simply show a html which indicates the parents and
    children relationship for each parent in my xml.

    Eric



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    eric zhou, Oct 30, 2004
    #3
  4. eric

    Joris Gillis Guest

    > I would like to simply show a html which indicates the parents and
    > children relationship for each parent in my xml.
    >


    Hi,

    Perhaps you are looking for something like this:

    <?xml version="1.0" ?>
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:eek:utput method="html" indent="yes"/>

    <xsl:template match="parents">
    <html>
    <head/>
    <body>
    <ul>
    <xsl:apply-templates mode="2html"/>
    </ul>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="*" mode="2html">
    <li>
    <span style="color:blue"><xsl:value-of select="local-name()"/></span>
    <ul>
    <xsl:apply-templates select="node()" mode="2html"/>
    </ul>
    </li>
    </xsl:template>
    </xsl:stylesheet>

    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
     
    Joris Gillis, Oct 30, 2004
    #4
  5. eric

    eric Guest

    Hi,Joris:

    I checked the html output. it is still a little bit different than I thought.

    How can we have something like:

    p1 1000
    c1 1001
    c2 1002
    p2 2000
    c3 2001
    p3 3000


    thanks.

    Eric


    "Joris Gillis" <> wrote in message news:<>...
    > > I would like to simply show a html which indicates the parents and
    > > children relationship for each parent in my xml.
    > >

    >
    > Hi,
    >
    > Perhaps you are looking for something like this:
    >
    > <?xml version="1.0" ?>
    > <xsl:stylesheet
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > version="1.0">
    >
    > <xsl:eek:utput method="html" indent="yes"/>
    >
    > <xsl:template match="parents">
    > <html>
    > <head/>
    > <body>
    > <ul>
    > <xsl:apply-templates mode="2html"/>
    > </ul>
    > </body>
    > </html>
    > </xsl:template>
    >
    > <xsl:template match="*" mode="2html">
    > <li>
    > <span style="color:blue"><xsl:value-of select="local-name()"/></span>
    > <ul>
    > <xsl:apply-templates select="node()" mode="2html"/>
    > </ul>
    > </li>
    > </xsl:template>
    > </xsl:stylesheet>
    >
    > regards,
     
    eric, Nov 1, 2004
    #5
  6. eric

    Joris Gillis Guest

    > How can we have something like:
    >
    > p1 1000
    > c1 1001
    > c2 1002
    > p2 2000
    > c3 2001
    > p3 3000
    >


    here you go:

    <?xml version="1.0" ?>
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:eek:utput method="html" indent="yes"/>

    <xsl:template match="parents">
    <html>
    <head>
    <style type="text/css">
    p {margin:0px}
    </style>
    </head>
    <body>
    <xsl:apply-templates mode="2html"/>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="*" mode="2html">
    <p style="padding-left:{count(ancestor::*)}em"><xsl:value-of select="name"/> <xsl:value-of select="id"/></p>
    <xsl:apply-templates select="child" mode="2html"/>
    </xsl:template>
    </xsl:stylesheet>

    regards,

    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
     
    Joris Gillis, Nov 1, 2004
    #6
  7. eric

    William Park Guest

    eric <> wrote:
    > Hi,Joris:
    >
    > I checked the html output. it is still a little bit different than I thought.
    >
    > How can we have something like:
    >
    > p1 1000
    > c1 1001
    > c2 1002
    > p2 2000
    > c3 2001
    > p3 3000



    If you can compile a Bash shell, then you can try

    start () {
    case ${XML_ELEMENT_STACK[1]} in
    child) [ "$parent_name" ] && printf '%s %s\n' $parent_{name,id}
    unset parent_{name,id}
    ;;
    esac
    }
    data () {
    local e=${XML_ELEMENT_STACK[1]}
    case $e in
    name|id)
    pp_append ${XML_ELEMENT_STACK[*]|/^(child|parent)$}
    strcpy $2_$e $1
    ;;
    esac
    }
    end () {
    case ${XML_ELEMENT_STACK[1]} in
    parent) printf '%s %s\n' $parent_{name,id}
    child) printf '\t%s %s\n' $child_{name,id}
    esac
    }
    xml -s start -d data -e end "`< file.xml`"

    Ref:
    http://freshmeat.net/projects/bashdiff/

    --
    William Park <>
    Open Geometry Consulting, Toronto, Canada
     
    William Park, Nov 2, 2004
    #7
    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?VGltOjouLg==?=

    HELP... Advanced Form... Need Guru

    =?Utf-8?B?VGltOjouLg==?=, Feb 16, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    345
    Leo Muller
    Feb 17, 2005
  2. Replies:
    1
    Views:
    3,637
    A. Bolmarcich
    May 27, 2005
  3. Replies:
    2
    Views:
    371
    Martin Jay
    Jun 23, 2006
  4. Chewbacca

    Need a Java guru to help a noob

    Chewbacca, Aug 9, 2006, in forum: Java
    Replies:
    2
    Views:
    332
    Mike Schilling
    Aug 9, 2006
  5. Jarrod Hyder

    Need a javascript guru (I need help!)

    Jarrod Hyder, Jan 27, 2005, in forum: Javascript
    Replies:
    1
    Views:
    90
Loading...

Share This Page