RE: [xsl] Expanding XML navigation

Subject: RE: [xsl] Expanding XML navigation
From: "Alex" <alex.scott@xxxxxxxxxxxxxx>
Date: Mon, 27 Sep 2004 16:16:13 +0100
Hi There,

I am still stuck with this one.
I want an expanding list.

Using the Identity transform I get that I can list my whole tree, and remove
nodes from it:
This is the entire tree:

<linkmap>
<page name="index">
    <page name="about">
      <page name="history"/>
    </page>
    <page name="events"/>
    <page name="contact">
      <page name="directions">
        <page name="new-york">
          <page name="manhattan">
            <page name="uptown"/>
          </page>
          <page name="bronx"/>
        </page>
        <page name="paris">
          <page name="left-bank"/>
          <page name="right-bank"/>
        </page>
      </page>
     </page>
</page>
</linkmap>

If am currently on the Manhattan page,
Then I just want to show:
1)the root nodes about-events-contacts
2)As I know that current node is Manhattan I want to find its root node
which is contact.
3)I then want to show the children of contact.
4)I then want to show all the descendants of the child of contact which is
also the ancestor of manhattan down to the children of manhattan.

The result tree should look something like this below:



<linkmap>
<page name="index">
    <page name="about"/>
    <page name="events"/>
    <page name="contact">
      <page name="directions">
        <page name="new-york">
          <page name="manhattan">
            <page name="uptown"/>
          </page>
          <page name="bronx"/>
        </page>
        <page name="paris">
        </page>
      </page>
     </page>
</page>
</linkmap>


Would it be easier for me to use a process of elimination as andrew has
suggested or a process of construction?

Alex.







> I am trying to produce a fragment from a linkmap XML which
> will represent the linkmap as the user opens up particular
> pages in the hierarchy. SImilar in appearance to
> http://ecolore.leeds.ac.uk/xml/about/site.xml?> lang=en
> I  use
> a page parameter to define which part will
> need its child element displayed.
>
> Then I intend to process this new accurate piece of XML via
> another stylesheet in order to style it.
>
> The problem I get is in preparing the first XML.
>
> I have used copy-of, starting from the Current page, however
> this shows all the descendants and I only want to show its
> children I presume you can't use a predicate with it?
>
> Then If I try using xsl:copy instead I am tying myself up in
> a mess. Any chance of some help?


You will need the identity transform with a no-op template:

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="x|y|z"/>

Where 'x' 'y' and 'z' are the names of the elements you don't want to
copy through.  Using your thought pattern this would be equivalent to
copy-of select with a predicate (which is of course not possible, as
copy-of select creates an exact copy).

Cheers
andrew

Current Thread