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

Re: selecting nodes - syntax?

Subject: Re: selecting nodes - syntax?
From: Oleg Tkachenko <olegt@xxxxxxxxxxxxx>
Date: Mon, 15 Oct 2001 12:08:32 +0200
selecting nodes code
Hello Denis!

Try the following:

<xsl:key name="akey" match="list/a" use="@code"/>
<xsl:template match="b">
<xsl:variable name="selected">
<xsl:for-each select="a">
<xsl:sort select="key('akey', @code)/@priority" order="ascending" data-type="number"/>
<xsl:if test="position() = 1">
<xsl:value-of select="@code"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
selected[<xsl:value-of select="$selected"/>]
</xsl:template>


Denis Kranjcec wrote:

Hello everyone.

I have problem with syntax when I want to select nodes.
Here is example XML:

<main>
	<list>
		<a code="1" priority="10" .../>
		<a code="2" priority="7" .../>
		<a code="3" priority="8" .../>
		<a code="4" priority="3" .../>
		<a code="5" priority="5" .../>
	</list>
	<elem>
		<b>
			...
			<a code="1"/>
			<a code="3"/>
			...
		</b>
		<b>
			...
			<a code="4"/>
			<a code="5"/>
			<a code="3"/>
			...
			<!--  hundreds of elements <b> -->
		</b>
		...
	</elem>
</main>

Every element <a> have lots of attributes (XSL-FO properties). There is cca.
20 different elements <a>.
Element <b> could have several elements <a>. Because of hundreds of elements
<b> I don't want that there is copy of <a> in every <b>. I would like to
have only attribute @code in element <a> that is same as @code in <a> with
all properties.
I want to select, for every <b> element, element <a> with lowest priority.

I tried with something like this:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="/">
		<xsl:apply-templates select="main/elem/b"/>
	</xsl:template>

	<xsl:template match="b">
		<xsl:variable name="selected">
			<xsl:for-each select="/main/a[@code = ./a/@code]"> <!-- I guess that
problem is that node . isn't <b> -->
				<xsl:sort data-type="number" select="@priority" order="ascending"/>
				<!-- debug --> debug[<xsl:value-of select="."></xsl:value-of>]
				<xsl:if test="position()=1">
					<xsl:value-of select="./@code"/>
				</xsl:if>
			</xsl:for-each>
		</xsl:variable>
		selected[<xsl:value-of select="$selected"/>]
	</xsl:template>
</xsl:stylesheet>


I don't know syntax to select element <a> with all properties.


What is correct syntax?

Any help is appreciated.
Thanks in advance,
Denis

P.S.
Sorry for my lousy english :-)



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list






-- Oleg Tkachenko Multiconn International, Israel


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.