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

Standard problem?

Subject: Standard problem?
From: "Nestel, Frank" <frank.nestel@xxxxxx>
Date: Mon, 9 Oct 2000 14:35:38 +0200
standard problem
Hi there,

I think this might be a standard problem: Having an XSL
which generates a certain subtree of a tree. I mean the
case, usually used in web site navigation.

E.g. having an xml which contains my site structure, 
like:

    <NODE id="A">
        <NODE id="A1"/>
        <NODE id="A2"/>
        <NODE id="A3">
            <NODE id="A3i"/>
            <NODE id="A3ii"/>
        </NODE>
    </NODE>
    <NODE id="B"/>
    <NODE id="C">
        <NODE id="C1"/>
        <NODE id="C2"/>
    </NODE>

I want to show an "extended branch" to every node. Eg. to
node "A3i", I'd like to have (except typos)

    <NODE id="A">
        <NODE id="A3">
            <NODE id="A3i"/>
            <NODE id="A3ii"/>
        </NODE>
    </NODE>
    <NODE id="B"/>
    <NODE id="C"/>

To Node B I'd like top get

    <NODE id="A"/>
    <NODE id="B"/>
    <NODE id="C"/>

To Node A3, this would result give

    <NODE id="A">
        <NODE id="A1"/>
        <NODE id="A2"/>
        <NODE id="A3">
            <NODE id="A3i"/>
            <NODE id="A3ii"/>
        </NODE>
    </NODE>
    <NODE id="B"/>
    <NODE id="C"/>

And so on. 

This is, to every node I'd like to have
all its parents and their siblings, I'd also like to
have the node and it's siblings and the direct 
childs of the node. 

The solution I currently have is only half way through
and looks somewhat complicated: 

	<xsl:stylesheet
	 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
	>
	<xsl:output indent="yes"/>
	
	<xsl:strip-space elements="*"/>
	
	<xsl:param name="page">A1i</xsl:param>
	
	<xsl:template match="/">
	    <xsl:value-of select="$page"/>
	    <xsl:for-each select="//NODE">
	        <xsl:apply-templates select="." mode="b"/>
	    </xsl:for-each>
	</xsl:template>

	<xsl:template match="NODE" mode="b">
	    <xsl:if test="@id=$page">
	        <xsl:variable name="dest" select="."/>
	        <xsl:variable name="destid" select="@id"/>
	        <xsl:for-each
select="ancestor::NODE/preceding-sibling::NODE|ancestor::NODE|ancestor::NODE
/following-sibling::NODE|preceding-sibling::NODE|following-sibling::NODE|.|c
hild::NODE">
	            <NODE>
		            <xsl:value-of
select="count(ancestor::NODE)"/>:<xsl:if test="@id = $destid">#</xsl:if>
	            <xsl:value-of select="@id"/>
      	      </NODE>
	        </xsl:for-each>
	    </xsl:if>
	</xsl:template>

	</xsl:stylesheet>	

Though I'm pretty sure, I could make it work and it is kind of
my personal homework, I still wonder if someone of the gurus
could come up with an instant and nice solution to this???

Thank you,

Frank 


 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.