Subject: Standard problem? From: "Nestel, Frank" <frank.nestel@xxxxxx> Date: Mon, 9 Oct 2000 14:35:38 +0200 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: question regarding ", Qi Rajkowski | Thread | Re: Standard problem?, David Carlisle |
Re: What's an "XML Fragment"?, Elliotte Rusty Harol | Date | Re: <P><H1></H1></P> to <P></P><H1>, Jeni Tennison |
Month |