[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Key function using key strings from msxsl:node-set generated node. Doesn't work?
Subject: RE: [xsl] Key function using key strings from msxsl:node-set generated node. Doesn't work? From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Sun, 17 Mar 2002 19:16:00 -0000 |
The key() function finds nodes within the current document (the document containing the context node). Within xsl:for-each select="xx:node-set()", the current document is the result tree fragment itself. I suspect you are looking for nodes in the original source document. Michael Kay Software AG home: Michael.H.Kay@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of > Macaulay,Malcolm (US) > Sent: 15 March 2002 05:34 > To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Key function using key strings from msxsl:node-set > generated node. Doesn't work? > > > I have a baffling problem. I'm trying to call the key > function using strings extracted from nodes coming from the > msxsl:node-set function. No matter what I try (i.e. > normalize-space etc) I can't get the same string from > msxsl:node-set as I do from the raw XML. > > There's a good reason why I don't want to use the Muenchian > method (which works fine). But I won't bore you with that. > I've created a simple example which illustrates the point. > Any help would be greatly appreciated. > > cheers > > Malcolm > > > <?xml version="1.0" encoding="UTF-8"?> > > <?xml-stylesheet type="text/xsl" href="Table from keys.xsl"?> > <People> > <Person> > <Name>Malcolm</Name> > <Address> > <No>10</No> > <Street>Lime Close</Street> > </Address> > </Person> > <Person> > <Name>Peter</Name> > <Address> > <No>20</No> > <Street>Milner Rd</Street> > </Address> > </Person> > <Person> > <Name>Mary</Name> > <Address> > <No>20</No> > <Street>Milner Rd</Street> > </Address> > </Person> > <Person> > <Name>John</Name> > <Address> > <No>20</No> > <Street>Milner Rd</Street> > </Address> > </Person> > </People> > > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:msxsl="urn:schemas-microsoft-com:xslt"> > <xsl:preserve-space elements="*"/> > <!-- > > key giving Person by the raw address string--> > <xsl:key name="PersonByAddress" match="/People/Person" > use="Address"/> > <!-- > > Address string key so unqiue addresses can a extracted > by Muenchian method--> > <xsl:key name="Address" match="/People/Person/Address" use="."/> > <!-- > > Alternative to Muenchian method - a ready-made list of > the unique addresses--> > <xsl:variable name="UniqueAddressStrings"> > <Address> > <No> 10</No> > <Street>Lime Close</Street> > </Address> > <Address> > <No> 20</No> > <Street>Milner Rd</Street> > </Address> > </xsl:variable> > <!-- > > --> > <xsl:template match="/"> > <!-- > > --> > <p>Works: Table contents keyed by unique > address strings, determined on-the-fly by Muenchian method</p> > <!-- > > --> > <table border="1" cellspacing="0"> > <tr> > <td>Address</td> > <td>No. of people</td> > </tr> > <xsl:for-each > select="/People/Person/Address[generate-id(.)=generate-id(key( > 'Address',.)[1])]"> > <xsl:sort select="."/> > <tr> > <td> > <xsl:value-of > select="."/> > </td> > <td> > <xsl:value-of > select="count(key('PersonByAddress',.))"/> > </td> > </tr> > </xsl:for-each> > </table> > <!-- > > --> > <p>Doesn't work: Table contents keyed by unique > address strings, extracted from a unique list of address > included in the XSLT. Requires msxsl:node-set, but cannot get > the same string nodes created by node-set function. > Normalize-space does not seem to help.</p> > <!-- > > --> > <table border="1" cellspacing="0"> > <tr> > <td>Address</td> > <td>No. of people</td> > </tr> > <xsl:for-each > select="msxsl:node-set($UniqueAddressStrings)/Address"> > <xsl:sort select="."/> > <tr> > <td> > <xsl:value-of > select="normalize-space(.)"/> > </td> > <td> > <xsl:value-of > select="count(key('PersonByAddress',normalize-space(.)))"/> > </td> > </tr> > </xsl:for-each> > </table> > </xsl:template> > </xsl:stylesheet> > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Key function using key st, Jeni Tennison | Thread | RE: [xsl] Key function using key st, Gennady Loskutov |
RE: [xsl] How to Disable Right Clic, Michael Kay | Date | RE: [xsl] general purpose filter st, Michael Kay |
Month |