Re: [xsl] Indenting Blocks in HTML Output

Subject: Re: [xsl] Indenting Blocks in HTML Output
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Sat, 20 Jul 2002 03:08:28 +0200
Why not passing the indentation as parameter to the statement_list template? Is it correct, that the statements can be deeper then 1 level and the indentation shell grow with the deepness?

<xsl:template match="statement[ *[1]/self::startblock and *[2]/self::statement_list and *[3]/self::endblock ]">
<xsl:param name="indent" select="''"/>
<xsl:value-of select="$indent"/>
<xsl:apply-templates select="*[1]"/>
<xsl:apply-templates select="*[2]">
<xsl:with-param name="indent" select="concat($indent, '&#160;&#160;&#160;&#160;')"/>
</xsl:apply-templates>
<xsl:value-of select="$indent"/>
<xsl:apply-templates select="*[3]"/>
</xsl:template>


<xsl:template match="statement_list">
  <xsl:param name="indent" select="''"/>
  <xsl:apply-template name="stament">
    <xsl:with-param name="indent" select="$indent"/>
  </xsl:apply-template>
</xsl:template>

Regards,

Joerg

xml@xxxxxxxxxxxxxxxxxxxxx wrote:
Hi,

I have an XML file, one of whose productions can be:

    <statement>
        <startblock/>
            <statement_list>...</statement_list>
        <endblock/>
    </statement>


This represents statement blocks in a traditional programming language, for example:

	if (condition)
	{
            statement1;
            statement2;
            ...
            statementN;
	}


My XSL file tries to create HTML from my XML file, and I would like it to indent statement blocks like these.

I initially tried something like this:

  <xsl:template match="statement[ *[1]/self::startblock and
*[2]/self::statement_list and *[3]/self::endblock ]">
	<xsl:apply-templates select="*[1]"/>
	<xsl:text>&#160;&#160;&#160;&#160;</xsl:text>
	<xsl:apply-templates select="*[2]"/>
	<xsl:apply-templates select="*[3]"/>
  </xsl:template>

But, this of course only indents the first line.  Not to be discouraged,
I tried using <dd>s, <ul>s, and <ol>s instead.  These do the correct
indenting, and look perfect in Internet Explorer and Mozilla.  However,
they put extra lines in when using the Java EditorPane class which is what
I ultimately need to display this in.

I'm wondering if there's a nice way of just doing the &#160; thing but
making it propogate down throughout the rest of the rules?  Otherwise if
anyone else has an idea on how to solve this, that would be great.

Thanks a lot!

Jared


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


Current Thread