Click to See Complete Forum and Search --> : how to get the sub sec title in XML


hpdp
12-11-2009, 10:05 AM
Hi, I have a xml document,

<body>
<sec sec-type="intro" id="S1">
<title>1. Introduction</title>
<p id="P2">The p2</p>
</sec>
<sec>
<title>2. method</title>
<sec>
<title>2.1 title</title>
<p>the 2.1 p</p>
<sec>
<sec>
</body>


Here's my XSLT
<xsl:template match="/">
<html>
<body bgcolor="#FFFFFF">
<xsl:apply-templates select="//body/sec"/>
</body>
</html>
</xsl:template>

<xsl:template match="//body/sec">
<center><font color="blue">
<br/><xsl:apply-templates select="title"/>
</font></center>
<br/>

<xsl:for-each select="descendant::p">
<xsl:apply-templates/>
<br/><br/>
</xsl:for-each>

<xsl:template select="descendant::sec">
<b><xsl:apply-templates select="title"/></b>
<xsl:for-each select="descendant::p">
<xsl:apply-templates/>
<br/><br/>
</xsl:for-each>
</xsl:template>

</xsl:template>


In the html output, I cannot see the sub sec title "2.1 title", though I got all the <p>.
How to get the sub sec title? Thanks!!!

hpdp
12-11-2009, 11:44 AM
I made a mistake. My code is
<xsl:template match="/">
<html>
<body bgcolor="#FFFFFF">
<xsl:apply-templates select="//body/sec"/>
</body>
</html>
</xsl:template>

<xsl:template match="//body/sec">
<center><font color="blue">
<br/><xsl:apply-templates select="title"/>
</font></center>
<br/>

<xsl:for-each select="descendant::p">
<xsl:apply-templates/>
<br/><br/>
</xsl:for-each>
</xsl:template>

I still cannot get the sub sec title "2.1 title".
Any suggestion? Thanks!!

rnd me
12-17-2009, 12:21 AM
<xsl:apply-templates select="//body/sec"/>


I still cannot get the sub sec title "2.1 title".
Any suggestion? Thanks!!

the above code is only selecting the first sec tag.

try:

<xsl:apply-templates select="/body//sec"/>