Subject: Re: [xsl] multiple values for the key From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sat, 02 Aug 2008 05:43:40 -0400 |
David, has given one possible solution, in XSLT 1.0 (which has advantage, that you don't need to use any extension function). Mike gave you a XSLT 2.0 version (which I feel, is cool).
Based on Mike's idea, here is another version using node-set extension function in XSLT 1.0,
<xsl:for-each select="key('x', exslt:node-set($x-values)/v)">
<xsl:for-each select="key('x',document('')/*/xsl:variable[@name='x-values']/v)">
t:\ftemp>type iyer.xml <?xml version="1.0" encoding="UTF-8"?> <root> <subroot id="11111"> <ccc>11</ccc> ==> needs to be picked <ddd>2005-08-26</ddd> <eee>aaaaa</eee> </subroot> <subroot id="11111"> <ccc>22</ccc> ==> needs to be picked <ddd>2005-08-26</ddd> <eee>bbbbb</eee> </subroot> <subroot id="11111"> <ccc>11</ccc> <ddd>2005-08-26</ddd> <eee>ccccc</eee> </subroot> <subroot id="11111"> <ccc>11</ccc> <ddd>2005-08-26</ddd> <eee>ddddd</eee> </subroot> <subroot id="11111"> <ccc>33</ccc> <ddd>2005-08-26</ddd> <eee>eeeee</eee> </subroot> </root>
t:\ftemp>type mukul.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="exslt" version="1.0">
<xsl:variable name="x-values"> <v>11</v> <v>22</v> </xsl:variable>
<xsl:template match="/root"> <result> <xsl:for-each select="key('x', exslt:node-set($x-values)/v)"> <value> <xsl:value-of select="eee" /> </value> </xsl:for-each> </result> </xsl:template>
t:\ftemp>type mukul.xml <?xml version="1.0" encoding="utf-8"?> <result> <value>aaaaa</value> <value>bbbbb</value> <value>ccccc</value> <value>ddddd</value> </result> t:\ftemp>type ken.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="x-values"> <v>11</v> <v>22</v> </xsl:variable>
<xsl:template match="/root"> <result> <xsl:for-each select="key('x',document('')/*/xsl:variable[@name='x-values']/v)"> <value> <xsl:value-of select="eee" /> </value> </xsl:for-each> </result> </xsl:template>
t:\ftemp>type ken.xml <?xml version="1.0" encoding="utf-8"?> <result> <value>aaaaa</value> <value>bbbbb</value> <value>ccccc</value> <value>ddddd</value> </result> t:\ftemp>type ken2.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/root"> <result> <xsl:for-each select="key('x',$x-values)"> <value> <xsl:value-of select="eee" /> </value> </xsl:for-each> </result> </xsl:template>
t:\ftemp>type ken2values.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="x-values-data"> <v>11</v> <v>22</v> </xsl:variable>
<xsl:variable name="x-values" select="document('')/*/xsl:variable[@name='x-values-data']/v"/>
t:\ftemp>type ken2.xml <?xml version="1.0" encoding="utf-8"?> <result> <value>aaaaa</value> <value>bbbbb</value> <value>ccccc</value> <value>ddddd</value> </result> t:\ftemp>rem Done!
-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] multiple values for the k, Mukul Gandhi | Thread | Re: [xsl] multiple values for the k, Mukul Gandhi |
RE: [xsl] alternative to repeatedly, Michael Kay | Date | Re: [xsl] multiple values for the k, Mukul Gandhi |
Month |