[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
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:
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Re: [xsl] selecting nodes - syntax?
Subject: Re: [xsl] selecting nodes - syntax? From: Oleg Tkachenko <olegt@xxxxxxxxxxxxx> Date: Mon, 15 Oct 2001 12:08:32 +0200 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] selecting nodes - syntax?, Denis Kranjcec | Thread | RE: [xsl] selecting nodes - syntax?, Denis Kranjcec |
RE: [xsl] Translate, Michael Kay | Date | Re: Schemas in XSLT 2.0 (Was: Re: [, Francis Norton |
Month |