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

Re: xsl: display only a specified node...

Subject: Re: xsl: display only a specified node...
From: Jörg Heinicke <Joerg.Heinicke@xxxxxx>
Date: Tue, 15 Oct 2002 11:55:59 +0200 (MEST)
use only as specified
> 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


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.