Inist-CNRS / node-jbj

Like XSL/XML but for JSON.
http://Inist-CNRS.github.io/jbj-playground/
13 stars 3 forks source link

Assert seems to lose context #7

Closed parmentf closed 9 years ago

parmentf commented 9 years ago

After a assert on a true value, already created preoperties are no more accessible.

Ex: input:

{
"content":
  {
    "json": 
    {
      "doi": "10.1007/1-4020-2365-0_11"
    }
  }
}

stylesheet:

{
  "$doi": {
    "path": "content.json.doi",
    "default":"0"
  },
  "$doiurl": {
    "assert": "doi!=0",
    "get": "doi",
   "prepend": "http://dx.doi.org/"
  }
}

output:

{
  "content": {
    "json": {
      "doi": "10.1007/1-4020-2365-0_11"
    }
  },
  "doi": "10.1007/1-4020-2365-0_11",
  "doiurl": "http://dx.doi.org/undefined"
}

Where doiurl should not contain undefined but the value of doi.

When you remove the assert part of the stylesheet, prepend works as intented.

parmentf commented 9 years ago

It seems that each action make the next one lose the context, so it is not proper to assert, but it remains annoying in assert case.

parmentf commented 9 years ago

To bypass this behavior, one case use the compute action, in conjunction with the ?: operator:

{
  "$doi": {
    "path": "content.json.doi"
  },
  "$doiurl": {
    "compute": "doi ? \"http://dx.doi.org/\"+doi : null"
  }
}

However, an assert keeping the original context would still be useful for more complicated cases.