Subject: RE: [xsl] xsl: display only a specified node... From: Jan Krattiger <jan.krattiger@xxxxxxxx> Date: Tue, 15 Oct 2002 14:07:01 +0200 |
a big thanks to you, joerg i didn't know the "descendant-or-self::" but that solved my problem! ta Jan -----Original Message----- From: Jörg Heinicke [mailto:Joerg.Heinicke@xxxxxx] Sent: Dienstag, 15. Oktober 2002 11:56 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] xsl: display only a specified node... > hi folks > > i'm not able to find a solution for that...and my xsl knowledge isn't that > good, so here's the situation: > > XML: > <sequence stype="ondemand" broadcastID="00"> > <mark ID="m0001" name="testh" time="0:00:00"> > <index> > <chapter lang="en" text="test1"/> > </index> > </mark> > <mark ID="m0002" name="" time="0:00:20" /> > <mark ID="m0003" time="0:00:40" /> > <mark ID="m0004" time="0:01:00" /> > <mark ID="m0005" time="0:01:20"> > <index> > <chapter lang="en" text="test2"/> > </index> > </mark> > </sequence> > <snip/> > <?xml version="1.0"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > <xsl:param name="page"/> i get this from a asp script, so i know which > "tree element" was clicked > <xsl:param name="markid"/> i get this from a asp script, so i know which > mark was clicked > <xsl:template match="/"> > ... > <body> > <xsl:apply-templates /> > </body> > ... > </xsl:template> > <xsl:template match="sequence"> > <xsl:if test="$page = 'sequence'"> > ... > <xsl:value-of select="@broadcastID" /> > ... > </xsl:if> > <xsl:apply-templates /> > </xsl:template> > <xsl:template match="mark"> > <xsl:if test="$page = 'mark'"> > <xsl:if test="@ID=$markid"> > ... > <xsl:value-of select="@name" /> > ... > </xsl:if> > </xsl:if> > <xsl:apply-templates /> > </xsl:template> As far as I understand it, the problem is in the above template. It matches on all <mark/> elements and via <xsl:apply-templates/> you tell the processor on all <mark/> to do further processing the childs. So every <index/> will be processed too. So you have to change your code insofar, that <xsl:apply-templates/> is processed only if $markid matches @ID. You code is not really straightforward to achieve your aim. Mostly it's a better to process only the elements you want and not all elements and decide there, which one should generate output. Example: a navigation tree: <root> <navitem id="nav1"/> <navitem id="nav2"/> <navitem id="nav3"> <navitem id="nav4"> <navitem id="nav5"/> <navitem id="nav6"/> </navitem> <navitem id="nav7"/> <navitem id="nav8"> <navitem id="nav9"/> <navitem id="nav10"/> </navitem> </navitem> <navitem id="nav11"/> </root> possible XSL: <xsl:param name="selected" select="'nav8'"/> <xsl:template match="root"> only process this navitem, where the currently selected navitem is a descendant or it is the currently selected navitem <xsl:apply-templates select="navitem[descendant-or-self::navitem/@id = $selected"/> </xsl:template> <xsl:template match="navitem"> the same here <xsl:apply-templates select="navitem[descendant-or-self::navitem/@id = $selected"/> </xsl:template> So assigned on your example only this <mark/> element will be processed that is selected, not the other one. And so only the selected <index/> can be processed. The descendant axis has a "performance problem": The more descendants there are, the longer the comparisons take of course. You have to test it. Furthermore with your multiple IDs, you don't seem to need the descendant axis so much. You should first select via $markid, later test which $page. And such a selecting takes less time than processing all elements even it's useless. Regards, Joerg > <xsl:template match="index"> > <xsl:if test="$page = 'index'"> > <xsl:apply-templates/> > </xsl:if> > </xsl:template> > <xsl:template match="chapter"> > ... > <xsl:value-of select="@text"/> > ... > </xsl:template> > > the problem is that i can't really "identify" the index... so i can't > check > which one the xsl should display > it should only show the info that belongs to the clicked tree-element. and > not all the childs from all the marks > as here in the bad example. > > and as always please excuse my poor english... > > thanks a lot > > > Jan M. Krattiger -- +++ GMX - Mail, Messaging & more http://www.gmx.net +++ NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen! XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xsl: display only a speci, Jörg Heinicke | Thread | [xsl] xsl:processing-instruction, DPawson |
RE: [xsl] XML document to WORD??, Gert Baudoncq | Date | Re: [xsl] XML document to WORD??, Jirka Kosek |
Month |