[OSM-newbies] XSLT question

Andrew Errington a.errington at lancaster.ac.uk
Wed Sep 16 10:52:53 BST 2009


On Wed, September 16, 2009 15:04, Renaud MICHEL wrote:
> Le mercredi 16 septembre 2009 à 05:30, Andrew Errington a écrit :
>>>> <xsl:template match="node[tag[@k='amenity' and @v=$amenity]]">
>>
>> I'm afraid I couldn't get this to work.  xsltproc complained.  :(
>>
>> I don't have the error message, but I could run it again and tell you
>> if you're interested.
>
> Well, I can't help you if I don't know what was the problem.

Ok, well if it's no trouble then I got this (using xsltpr:

XPath error : Undefined variable
tag[@k='amenity' and @v=$amenity]
                                ^
compilation error: file test.xsl line 23 element template
Failed to compile predicate


The caret is under the last ] (if you have a monospaced font).

<snip>
> If you want to do a sum you must have a node-set, which you can't have
> with key(), so you will need to reference the elements directly (which is
> a lot slower than key() ), like this (the way being the current node)
>
> <xsl:variable name="nodes" select="../node[@id=current()/nd/@ref]"/>
> <xsl:value-of select="sum($nodes/@lat) div count($nodes)"/>
> <xsl:value-of select="sum($nodes/@lon) div count($nodes)"/>
>
> The trick here is that the construct @id=current()/nd/@ref which compare
> one value (@id) with a node-set (current()/nd/@ref) is true if any of the
> selected @ref is equal to @id.

I understand the explanation.  Whether I can use it is another matter.  :)
 Thanks for your help so far.  I'll try your code and report back.

Best wishes,

Andrew





More information about the newbies mailing list