[j-nsp] Conditional statement in XPath predicates
Martin T
m4rtntns at gmail.com
Mon Mar 12 10:18:34 EDT 2018
On Fri, Mar 9, 2018 at 8:39 PM, Phil Shafer <phil at juniper.net> wrote:
> 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
Jonathan,
this is really elegant solution! Thanks!
Martin
More information about the juniper-nsp
mailing list