[j-nsp] Conditional statement in XPath predicates

Phil Shafer phil at juniper.net
Fri Mar 9 13:39:18 EST 2018


Jonathan Looney writes:
>Actually, come to think of it, this (while untested) will probably work and
>be much simpler:
>
>param $interface = "undef";
>
>for-each ($result/physical-interface[$interface == "undef" || name == $interface]) {

Yup.  The ternary operator ("?:") turns into an <xsl:choose>, so it's
not suitable for all expression locations.  SLAX is actually hiding quite
a fair bit of XSLT plumbing behind "?:".

% slaxproc --slax-to-xslt --partial --name -
var $x = favorite-color ? "blue" : "green";
^D
<xsl:variable name="slax-ternary-1">
  <xsl:choose>
    <xsl:when test="favorite-color">
      <xsl:copy-of select=""blue""/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:copy-of select=""green""/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:variable>
<xsl:variable xmlns:slax="http://xml.libslax.org/slax" name="x" select="slax:value($slax-ternary-1)"/>

Thanks,
 Phil


More information about the juniper-nsp mailing list