RE: Re: Proposal: has-name-match()

"Derose, Steve (NIH/NLM/NCBI) [C]" <[email protected]> Fri, 26 Jan 2007 10:13:08 -0500
Newsgroups gmane.text.xml.xslt.extensions
Message-ID <[email protected]>
It seems to me this would be better handled by more general functions,
for example to compare whether a given range out of two nodesets was
identical, or perhaps to assemble the names of nodes just as str:concat
does for the string-values of nodes. Any of those would buy more
functionality for less effort.

For example, perhaps:

   subrange(node-set, start-pos, end-pos)

   node-set-eq(node-set1, node-set2)

   or concat-names(node-set) (now *that's* a function I could get
behind!)

These seem like more fundamental functionality, though they can all be
gotten already one way or another.

Hmmm. I just wrote your function without something like concat-names(),
and it does seem to be a bit of a pain (though of course, since we have
functions you can just do it once; it's not especially slow):

   <xsl:variable name="names-a">
      <xsl:for-each select="$a/ancestor::*[position() <= $distance]">
	   <xsl:value-of select="concat(name(),' ')"/>
	</xsl:for-each>
   </xsl:variable>
   <xsl:variable name="names-b">
      <xsl:for-each select="$b/ancestor::*[position() <= $distance]">
	   <xsl:value-of select="concat(name(),' ')"/>
	</xsl:for-each>
   </xsl:variable>
   <xsl:if test="$names-a = $names-b"> 1 </xsl:if>

Do you think this is really a common enough need to warrant its own
extension? I'd be much more comfortable with a more general function
that would facilitate it, such as concat-names() (such a function, for
example, would let you write the above without foreach, all in one
expression. In XSLT 2 with a "real" for, it's also easier.

Steve

> ""John L. Clark"" <[email protected]> wrote in message 
> news:[email protected]...
> >I propose a new EXSLT function that might be called  
> >`has-name-match()`.  The signature for this function would 
> be similar  
> >to the following:
> >
> >  boolean has-name-match(node-set a, node-set b, integer distance?)
> >
> > This function would examine the first node of both a and b and 
> > determine if the name of each element on the 
> ancestor-or-self axis for 
> > each of these nodes is the same, up to distance from each 
> node.  More 
> > precisely, `has-name-match()` returns true if and only if
> > (local-name(a) = local-name(b) and namespace-uri(a) = 
> namespace-uri(b) 
> > and has-name-match(a/.., b/.., distance - 1)).