Search

Hello,

if I have following XSL for example:

<xsl:template match="entry">
  <xsl:value-of select="/data/locations/entry[@id = location/item/@id]" />
</xsl:template>

Where does the first @id point to? And the second one (location/...)?

The first @id points to the id attribute's value of the entry xml node. The second @id references the item node's id attribute's value.

So this value-of selects all locations entry nodes with an id value that is equal to the location/item id value.

The first @id:

Does it point to entry that template is matching? Or the locations/entry? And the second one. Does it point to location child node of entry that template is matching?

If I use numeric value instead of location/item/@id, this XPath works, but with that location/... it doesn't work...

Edit: I need the location/item/@id to point to entry that template is matching... The problem is, I think, to what they're relative to.

I got it working by making the second @id variable and using it in comparison. But it would be good to know how to make this without variable.

Both @id are in the context of /data/locations/entry:

  • The first @id points to
    /data/locations/entry/@id
  • The second location/item/@id points to
    /data/locations/entry/location/item/@id

If you have to compare your @id with the entry/@id you are matching with your template, try this:

<xsl:value-of select="/data/locations/entry[@id = current()/location/item/@id]" />

current() references your template context.

Thanks Nils, that worked.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details