Re: [xsl] Subsection Formatting

Subject: Re: [xsl] Subsection Formatting
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Fri, 28 Jun 2002 08:53:59 +0200
<xsl:template match="SubSection">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="ssHdr">
  <h3><xsl:apply-templates/></h3>
</xsl:template>

<xsl:template match="TextPara">
  <p><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="Introduction">
  <html>
    <head>
      <title>
        <xsl:apply-templates select="IntroTitle"/>
      </title>
      <link rel="stylesheet" href="novabasic.css" type="text/css"/>
    </head>
    <body>
      <h2 align="center"><xsl:apply-templates select="IntroTitle"/></h2>
      <xsl:apply-templates select="ProbStmt"/>
      <!-- where does ssHdr come from? there is no ssHdr in DTD -->
      <h3><xsl:value-of select="ssHdr"/></h3>
    </body>
  </html>
</xsl:template>

For a more or less arbitrary XML code, it's mostly better to use <xsl:apply-templates/> instead of <xsl:value-of/>. Your problem was the <xsl:value-of select="ProbStmt"/>, which returns a concatenated string of all the descendant text nodes in <ProbStmt/>.

Regards,

Joerg


Jack Cane wrote:
I'm quite new at xml/xslt. Have created a dtd and style sheet which work, to
a point. The problem is with separation and formatting of subsection
elements. At present the subsection title and all text paragraphs are in one
paragraph.

Would appreciate some feedback on where I am going wrong here.

========================================

Here is the xsl content:

<?xml version = "1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns="dissertation.dtd"
                xmlns:html="http://www.w3.org/1999/xhtml";
                version="1.0">
	<xsl:template match="SubSection">
		<h3><xsl:value-of select="ssHdr"/></h3>
		<p><xsl:value-of select="TextPara"/></p>
	</xsl:template>
  <xsl:template match="Introduction">
    <html>
      <head>
        <title>
          <xsl:value-of select="IntroTitle"/>
        </title>
        <link rel="stylesheet" href="novabasic.css" type="text/css"/>
      </head>
      <body>
        <h2 align="center"><xsl:value-of select="IntroTitle"/></h2>
        <xsl:value-of select="ProbStmt"/>
        <h3><xsl:value-of select="ssHdr"/></h3>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

========================================

And here is the relevant part of the dtd:

  <!ELEMENT SubSection (ssHdr, TextPara+)>
    <!ELEMENT ssHdr (#PCDATA)>
    <!ELEMENT TextPara (#PCDATA)>

  <!ELEMENT Section (SectHdr, SubSection+)>
    <!ELEMENT SectHdr (#PCDATA)>
    <!ELEMENT SubSect (SubSection)>

  <!ELEMENT Chapter (ChapHdg, Section+)>
    <!ELEMENT ChapHdg (#PCDATA)>
    <!ELEMENT Sect (Section)>

<!ELEMENT Introduction (IntroTitle, ProbStmt)>

    <!ELEMENT IntroTitle (SectHdr)>
    <!ELEMENT ProbStmt (SubSection)>

========================================

tks,

jwc


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


Current Thread