|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: use of xsl:key in cross-referencing
Xiaocun,
Sorry I've been off the list-- out here in the hills of WV, my phone line is down, and I have to hoof it to my neighbor's to get a net connection. Anyhow, you are pretty close to your solution: <xsl:key name="QuestionnaireKey" match="row[count(cell)=3]/cell[2]" use="."/> <xsl:key name="QuestionnaireKey" match="row[count(cell)=2]/cell[1]" use="."/> Instead of recognizing the different groups by their row number, I decided to use the count of their cells. If I have three cells, I know this is a row like <row row="17"> <cell column="1">Questionnaire B</cell> <cell column="2">QB</cell> <cell column="3">Questionnaire B, empty with no questions</cell> </row> and the Questionnaire identifier is the second cell (whose value is 'QB'). If I have only two cells, however, my data is like this <row row="28"> <cell column="1">QA</cell> <cell column="2">Questionnaire A, Question 2</cell> </row> and the identifier is the first cell (value is 'QA'). If this assumption does not hold for your data, you need to adjust the match patterns in the key declarations to whatever does work. On the data as you provided it, the Questionnaire key retrieves either one of these kinds of identifiers by the correct value ('QA', 'QB' or 'QC'). Then if I have <xsl:template match="/">
<xsl:apply-templates
select="//cell[key('QuestionnaireKey',.) and
count(.|key('QuestionnaireKey',.)[1])=1 ]"/>
</xsl:template>I select //cell ... all the cells in the document... [key('QuestionnaireKey',.) ... testing whether this cell's value is among my Questionnaire identifiers (note this introduces a very subtle assumption about these identifiers, namely that they are unique strings) ... and count(.|key('QuestionnaireKey',.)[1])=1 ] ... making sure if it is an identifier, it's the first one (Muenchian grouping). I think you can see this is a cleaned-up version of what you almost had.... Cheers, Wendell At 06:36 PM 3/20/2003, you wrote: Hi, Wendell:
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








