Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Performance referencing global parameter data [Thread Next] Re: Performance referencing global parameter dataTo: NULL Date: 1/3/2007 3:36:00 PM > I tried the following > > .... > .... > <!-- Define Keys that will index the configuration--> > <xsl:key name="documents" match="/*" use="name()"/> Richard, You need to gain some experience using keys. The expression to be specified in the "match" attribute of xsl:key is a *match pattern" as the name implies, not an absolute XPath expression. In the case above there is no need to specify a key that will index only one single node -- the top element of an xml document. > <xsl:key name="document_itemsincluded" match="/*/IncludedItems/*" > use="concat(name(../..),'_',name())"/> This one is also very strange as it will index any "level-3" elements children of "IncludedItems". Here they are identified by the concatenation of the name of the top element (which is only one and never changes!) and (their) the name of the 3rd-level element. In this case just the following would be sufficient: <xsl:key name="document_itemsincluded" match="/*/IncludedItems/*" use="name()"/> The same goes for this one: > <xsl:key name="document_itemsexcluded" match="/*/ExcludedItems/*" > use="concat(name(../..),'_',name())"/> Going further... > <xsl:for-each select="$configuration-nodeset/*"> > <xsl:for-each select="key('documents',name())"/> > </xsl:for-each> As said above the key() function in this case selects just the top element named "documentType". There is no need for the key function, as the parent <xsl:for-each instruction already selects exactly this top element. Also, it is very strange that nothing is done within the inner xsl:for-each ??? My analysis will stop here. It appears that you probably have enough information about the nature of the problems you are experiencing. Cheers, Dimitre Novatchev. "Richard Collette" <richard.collette@g...> wrote in message news:1167860931.641663.177670@v...... > Dimitri, > > I looked at this a little bit closer. Your example shows processing > as happening for each item in my configuration. What I wish to do is > get the appropriate configuration information for each item encountered > in the document being transformed. I'm not sure this is possible > since there are two different contexts involved. > > I tried the following > > .... > .... > <!-- Define Keys that will index the configuration--> > <xsl:key name="documents" match="/*" use="name()"/> > <xsl:key name="document_itemsincluded" match="/*/IncludedItems/*" > use="concat(name(../..),'_',name())"/> > <xsl:key name="document_itemsexcluded" match="/*/ExcludedItems/*" > use="concat(name(../..),'_',name())"/> > > <!-- Starting at the root element of the dxl document --> > <xsl:template match="/"> > <!-- Create keys to configuration elements--> > <xsl:for-each select="$configuration-nodeset/*"> > <xsl:for-each select="key('documents',name())"/> > </xsl:for-each> > <xsl:for-each select="$configuration-nodeset/*/IncludedItems/*"> > <xsl:for-each > select="key('document_itemsincluded',concat(name(../..),'_',name()))"/> > </xsl:for-each> > <xsl:for-each select="$configuration-nodeset/*/ExcludedItems/*"> > <xsl:for-each > select="key('document_itemsexcluded',concat(name(../..),'_',name()))"/> > </xsl:for-each> > ... > .. > </xsl:template> > > <!-- Template for all document items--> > <xsl:template match="d:item"> > <xsl:param name="documentName"/> > .. > .. > <xsl:variable name="itemConfiguration" > select="key('document_itemsincluded',concat($documentName,'_',$normalizedElementName))"/> > ... > </xsl:template> > > And this does not appear to work. > > > Dimitre Novatchev wrote: >> <richard.collette@g...> wrote in message >> news:1167847756.234534.79320@h...... >> > To the best of my knowledge, there is no way in XSL 1.0 to key values >> > passed in a global parameter since xsl:key will not accept variables. >> > So I am left with the worst performing aspect of my xsl being lookups >> > to parameterized configuration information which looks like: >> > >> > <xsl:param name="config"> >> > <documentType miscControlAttributes=""> >> > <itemName miscControlAttributes=""/> >> > <itemName2 miscControlAttributes=""/> >> > </documentType> >> > </xsl:param> >> > >> > The configuration is then stored as a nodeset >> > <xsl:variable name="configuration-nodeset" >> > select="msxsl:node-set($configuration)"/> >> >> This is not necessary for static (not dynamically generated parameters). >> One >> can simply write: >> >> >> <xsl:variable name="configuration-nodeset" >> select="document('')/*/xsl:param[@name='config'"/> >> >> > >> > For each documentType node in the input, I retrieve the document level >> > configuration into a variable: >> > <xsl:variable name="documentConfiguration" >> > select="$configuration-nodeset/*[translate(name(), $lc, >> > $uc)=translate(current()/@form,$lc,$uc)]"/> >> > >> > The document nodes are, unfortunately, case insensitive coming from the >> > source, so I have to perform a translation to upper case for >> > comparison. >> > >> > The template for processing document items is called, passing in the >> > document configuration >> > <xsl:apply-templates select="*"> >> > <xsl:with-param name="documentConfiguration" >> > select="$documentConfiguration"/> >> > </xsl:apply-templates> >> > >> > The document item template then does a lookup to the item configuration >> > <xsl:template match="d:item"> >> > <xsl:param name="documentConfiguration"/> >> > <xsl:variable name="itemConfiguration" >> > select="$documentConfiguration/*[translate(name(),$lc,$uc)=translate($normalizedElementName,$lc,$uc)]"/> >> > </xsl:template> >> > >> > Does anyone know of a better pattern for looking up parameterized >> > configuration info that is compatible with XSL 1.0? >> > >> >> The key() function operates on the current document. This means that >> xsl:key >> can be used to index any document, including a dynamically created one. >> >> This design pattern is well known and can be implemented as in the >> example >> below: >> >> <xsl:for-each select="<root-node-of-some-document"> <!-- makes >> <some-document> the current document --> >> >> <xsl:for-each select="key('some-key', <some-value>)"> <!-- Creates >> an >> index for the given key the first time it is referenced by a key() >> function >> for the current document --> >> >> <!-- do whatever is necessary with each node selected by the >> key() >> function --> >> >> </xsl:for-each> >> </xsl:for-each> >> >> For more examples do have a look at: >> http://dpawson.co.uk/xsl/sect2/N4852.html#d5954e181 >> >> and generally at: >> http://dpawson.co.uk/xsl/sect2/N4852.html >> >> >> Hope this helped. >> >> Cheers, >> Dimitre Novatchev > | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
