[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Stylesheet assistance

Subject: Re: Stylesheet assistance
From: "Nikolai Grigoriev" <grig@xxxxxxxxxxx>
Date: Wed, 26 Jul 2000 01:11:03 +0400
indentation stylesheet
Daniel,

> Any suggestions on how do do the following?

I would suggest passing indentation as a parameter:

<xsl:template match="a1|a2|a3|a4|a5|a6">
  <xsl:param name="indentation" select="0"/>
  <p>

    <!-- If an indentation is greater than 0, create a style attribute -->
    <xsl:if test="$indentation &gt; 0">
      <xsl:attribute name="style">
        <xsl:text>margin-left: </xsl:text>
        <xsl:value-of select="$indentation"/>
        <xsl:text>px</xsl:text>
      <xsl:attribute>
    </xsl:if>

    <!-- If an indentation is greater than 0 or <b/> is present, -->
    <!-- increase the indentation of children by 12-->
    <xsl:choose>
      <xsl:when test="b or $indentation &gt; 0">
        <xsl:apply-templates>
          <xsl:with-param name="indentation" select="$indentation+12"/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
    </xsl:choose>

  </p>
</xsl:template>

You can also solve this without parameters, but then you will need to calculate
the offset individually for every <a#> element, climbing up the document tree by
a dedicated recursive template:

<xsl:template match="a1|a2|a3|a4|a5|a6">
  <p>

    <!-- If an indentation trigger is set, create a style attribute -->
    <xsl:if test="ancestor::*/b">
      <xsl:attribute name="style">
        <xsl:text>margin-left: </xsl:text>
        <xsl:apply-templates select="." mode="count-indentation"/>
        <xsl:text>px</xsl:text>
      <xsl:attribute>
    </xsl:if>

    <xsl:apply-templates/>
  </p>
</xsl:template>


<!-- Calculate the offset: on each step up the doctree, -->
<!-- add 12 to indentation; stop when <b/> is found. -->
<xsl:template match="*" mode="count-indentation"/>
  <xsl:param name="indentation" select="0"/>
  <xsl:choose>
    <xsl:when test="b"><xsl:value-of select="$indentation"</xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates select=".." mode="count-indentation">
        <xsl:with-param name="indentation" select="$indentation+12"/>
      </xsl:apply-templates>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Seemingly, the first solution would generate less overhead than the second
one. Note also that they behave differently when several <b/>'s are
present on ancestors of an element (situation not excluded by your DTD):

- the first thing will indent from the topmost <b/> ignoring lower <b/>'s;
- the second one will reset indents to 0 on every <b/>.

Regards,
Nikolai Grigoriev
RenderX





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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.