|
Subject: RE: [xsl] Navigation / node-set From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Wed, 14 May 2008 18:28:43 +0100 |
You basically need to collapse the "matching" condition into a predicate so
you can say
<xsl:for-each select="preceding-sibling::*[PRED][1]">
That's easy in XSLT 2.0 where you can put your code into a function and call
the function from your predicate:
<xsl:for-each select="preceding-sibling::*[f:matching(.)][1]">
<xsl:function name="f:matching" as="xs:boolean">
<xsl:param name="node" as="node()"/>
<xsl:variable name="wx">
<xsl:if test="contains(substring(kbase/title, 1, 2),$witem)">
<xsl:value-of select="(@id)"/>
</xsl:if>
</xsl:variable>
<xsl:sequence select="string-length($wx) > 0">
</xsl:function>
But in fact this can all be collapsed into a simple XPath expression anyway:
<xsl:for-each select="preceding-sibling::*[contains(substring(kbase/title,
1, 2),$witem) and string-length(@id)>0][1]">
You might not need the (string-length(@id)>0) part of the condition.
Also I strongly suspect that contains(substring(kbase/title, 1, 2),$witem)
can be rewritten
substring(kbase/title, 1, 2) = $witem
or possibly even
starts-with(kbase/title, $witem)
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: nenad@xxxxxxxxxxxxxxx [mailto:nenad@xxxxxxxxxxxxxxx]
> Sent: 14 May 2008 18:07
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Navigation / node-set
>
> Hi, my problem is that with this code
> instead of displaying the first matching preceding-sibling I
> display all of them that precede.
> How I can diplay just the first matching preceding-sibling?
> Thanks
>
>
>
> <xsl:template name="randomsearch">
> <xsl:variable name="selcat" select="$SelectCategories"/>
> <xsl:variable name="selran" select="$SearchedString"/>
> <xsl:variable name="filart" select="$FilterArticles"/>
> <xsl:variable name="showsingle" select="$ShowSingleTechno"/>
>
>
> <xsl:variable name="witem">
>
> <xsl:for-each select="(./kbase//title)">
> <xsl:value-of select="substring(., 1,
> 2)"/></xsl:for-each></xsl:variable>
>
>
>
> <xsl:for-each select="preceding-sibling::*">
> <xsl:variable name="wx">
> <!--<xsl:value-of select="substring(kbase/title, 1, 2)"/>;;-->
>
> <xsl:if test="contains(substring(kbase/title, 1, 2),$witem)">
> <!--<xsl:if test="position() != last() ">-->
> <xsl:value-of select="(@id)"/>
> </xsl:if>
> <!--</xsl:if>-->
> <!---->
> </xsl:variable>
>
>
> <xsl:if test="string-length($wx) > 0">
> <!-- <xsl:if test="position()=1">-->
> <b>
> <i>
> <a>
> <xsl:attribute name="href">
> http://localhost:1313/?ShowSingleTechno=<xsl:value-of
> select="$wx"/>&SelectCategories=<xsl:value-of
> select="$selcat"/>&SearchedString=<xsl:value-of
> select="$selran"/>&FilterArticles=<xsl:value-of
> select="$filart"/>
> </xsl:attribute>PREVIOUS
> </a>
>
> </i>
> </b>
> </xsl:if>
> </xsl:for-each>
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Navigation / node-set, Martin Honnen | Thread | Re: [xsl] Navigation / node-set, Mukul Gandhi |
| Re: [xsl] Navigation / node-set, Martin Honnen | Date | Re: [xsl] Navigation / node-set, Mukul Gandhi |
| Month |