You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Chitharanjan Mohandas <cd...@accordiasys.com> on 2002/09/20 21:43:12 UTC
Urgent: Help in XSLT ..........
I have the following requirement.. I am sorry If I have posted
to the woring site. Since cocoon uses XSLT a lot, I guess I
will be better helped here.... Please do help me on this...
Consider the following XML....
I need to extract the description for the language
which appears first when sorted alphabetically.....
In this case I need the description for lang "de" i.e German Descrciption...
The script should extract only for the language de...
<Item>
<description>
<lang>en</lang>
<value>Description</value>
</description>
<description>
<lang>de</lang>
<value>German Description</value>
</description>
<description>
<lang>es</lang>
<value>Spanish Description</value>
</description>
</Item>
Could any one of you please advice me on how to build
an XSLT script to solve this issue...
Thanks and regds,
Chiths
PS: How does one return a XML node from a template....
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faq/index.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>
Re: Urgent: Help in XSLT ..........
Posted by "J.Pietschmann" <j3...@yahoo.de>.
Chitharanjan Mohandas wrote:
> I have the following requirement.. I am sorry If I have posted
> to the woring site. Since cocoon uses XSLT a lot, I guess I
> will be better helped here....
Close, but no cigar. The best place to ask XSLT related
questions is still the XSL list:
http://www.mulberrytech.com/xsl/xsl-list/
THey have a FAQ and an archive there.
> Consider the following XML....
>
> I need to extract the description for the language
> which appears first when sorted alphabetically.....
>
> In this case I need the description for lang "de" i.e German Descrciption...
> The script should extract only for the language de...
...
> Could any one of you please advice me on how to build
> an XSLT script to solve this issue...
The easiest way is to use
<xsl:template match="Item">
<xsl:for-each select="description">
<xsl:sort select="lang"/>
<xsl:if test="position()=1">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
<xsl:template>
This is not very efficient if you have a real lot
of descriptions (run time is O(n*log(n)) instead of
O(n)), but then, I don't think there is an efficient
solution without using an extension function for
lexical string comparisions.
J.Pietschmann
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faq/index.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>