need help from xsl guru

E

eric

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>
 
E

eric zhou

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

Eric
 
J

Joris Gillis

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,
 
E

eric

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
 
J

Joris Gillis

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,
 
W

William Park

eric said:
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/
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top