Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 08:49 AM
eric
Guest
 
Posts: n/a
Default need help from xsl guru

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>
  #2  
Old July 20th, 2005, 08:49 AM
rumionfire@gmail.com
Guest
 
Posts: n/a
Default Re: need help from xsl guru

> I write an xml file structure and I would like to write an xsl file
for it.[color=blue]
> Can someone give me some help??[/color]

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

  #3  
Old July 20th, 2005, 08:49 AM
eric zhou
Guest
 
Posts: n/a
Default Re: need help from xsl guru

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!
  #4  
Old July 20th, 2005, 08:49 AM
Joris Gillis
Guest
 
Posts: n/a
Default Re: need help from xsl guru

> I would like to simply show a html which indicates the parents and[color=blue]
> children relationship for each parent in my xml.
>[/color]

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:output 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-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
  #5  
Old July 20th, 2005, 08:50 AM
eric
Guest
 
Posts: n/a
Default Re: need help from xsl guru

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" <roac@pandora.be> wrote in message news:<opsgobo7k5yf9v9r@news.pandora.be>...[color=blue][color=green]
> > I would like to simply show a html which indicates the parents and
> > children relationship for each parent in my xml.
> >[/color]
>
> 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:output 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,[/color]
  #6  
Old July 20th, 2005, 08:50 AM
Joris Gillis
Guest
 
Posts: n/a
Default Re: need help from xsl guru

> How can we have something like:[color=blue]
>
> p1 1000
> c1 1001
> c2 1002
> p2 2000
> c3 2001
> p3 3000
>[/color]

here you go:

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

<xsl:output 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-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
  #7  
Old July 20th, 2005, 08:50 AM
William Park
Guest
 
Posts: n/a
Default Re: need help from xsl guru

eric <ezhou@shaw.ca> wrote:[color=blue]
> 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[/color]


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 <opengeometry@yahoo.ca>
Open Geometry Consulting, Toronto, Canada
 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles