This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: building hierarchy from path string


Hi John-Mason,

>     <xsl:key name="children" match="node" use="substring(@path, 1,
> @depth * $tierChars)" />

Unfortunately you can't use variables in keys :(  [It's supposed to
avoid circular definitions - variables defined using keys using
variables - but actually it's just a pain in the neck.]

But since that value's coming from the source document, you can do:

<xsl:key name="children" match="node"
         use="substring(@path, 1, @depth *
                                  /tree/descriptor/@chars-per-tier)" />

And you can use the variable later on in the document as you are
doing.

If you were passing it in as a parameter it would be more difficult -
the way out would be to substitute the uses of the key for the full
horror of the paths:

<xsl:template match="tree">
  <tree>
    <xsl:apply-templates
      select="node[not(substring(@path, 1, @depth * $tierChars))]" />
  </tree>
</xsl:template>

<xsl:template match="node">
  <node name="{@name}">
    <xsl:apply-templates
      select="../node[substring(@path, 1, @depth * $tierChars) =
                      substring(current()/@path, 1,
                                (@depth + 1) * $tierChars))">
      <xsl:sort select="@path" />
    </xsl:apply-templates>
  </node>
</xsl:template>

But this is a lot less efficient than using the key and should be
avoided if possible.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]