This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
How to express a select attr in for-each for conditional or nonconditonal case.
- From: "E100 SFYang" <SFYang at unisvr dot net dot tw>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 20 Dec 2001 11:35:19 +0800
- Subject: [xsl] How to express a select attr in for-each for conditional or nonconditonal case.
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi, listers,
I use contains function to get the selected item defined
by select attr of param element. such as;
<xsl:for-each select="$source[contains($keywrd,.)]">
Of course using this expression for empty param, nothing will be
displayed.
I wonder how to modify the above select att to be able to display
1. selected items when keywrd is not empty.
2. all items when keywrd is empty.
Thanks for any help in advance.
Sun-fu Yang
sfyang@unisvr.net.tw
*** simplified xml file **
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<docs>
<item>a</item>
<item>b</item>
<item>c</item>
</docs>
*** xsl file **
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="sourcekey" match="item" use="."/>
<xsl:variable name="source"
select="/docs/item[generate-id(.)=generate-id(key('sourcekey',.)[1])]"/>
<xsl:param name="keywrd" select="'a,b'"/>
<xsl:template match="/">
<xsl:for-each select="$source[contains($keywrd,.)]">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list