Re: AW: Nodeset displayed as <ul>-list

Subject: Re: AW: Nodeset displayed as <ul>-list
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 01 Aug 2000 20:25:14 +0100
Conny,

>Ok this will worked fine for the full node-set, but how can i use my
>node-set (ancestor::* | ancestor::*/child::*)?

I don't know whether you have $navid defined as a global parameter/variable
or only locally.  Either way, you can make a check on whether the current
nav element is an ancestor of the $navid element before deciding whether or
not to show its children.

Here is a version of Ben's code that takes into account the start and end
depth as well as the $navid.

<xsl:param name="navid" select="'124'" />
<xsl:param name="sd" select="'1'" />
<xsl:param name="ed" select="'3'" />

<xsl:template match="tree">
  <ul>
    <xsl:apply-templates select="//nav[count(ancestor::*) = $sd]" />
  </ul>
</xsl:template>

<xsl:template match="nav">
  <xsl:if test="count(ancestor::*) &lt;= $ed">
    <li>
      <xsl:if test="@title">
        <xsl:value-of select="@title"/>
      </xsl:if>
      <xsl:if test="@group">
        <b><xsl:value-of select="@group"/></b>
      </xsl:if>
      <xsl:if test="descendant::nav[@id = $navid] and
                    count(ancestor::*) != $ed">	
        <ul><xsl:apply-templates /></ul>
      </xsl:if>
    </li>
  </xsl:if>
</xsl:template>

If $navid is not a global variable/parameter, then you will have to pass it
as a parameter from template to template.

A couple of things to note about your original code:

1. there's no need to use the boolean() function within tests as the
content of the test attribute (on xsl:if and xsl:when) is automatically
converted to a boolean value

2. the ids that you're giving your nav elements aren't valid IDs under XML
(they can't start with a number), which means that the id() function that
you were using shouldn't work

I hope this helps,

Jeni

Dr Jeni Tennison
Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@xxxxxxxxxxxxxxxx


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


Current Thread