Layer7 API Management

 View Only
  • 1.  Can a variable set in "Set Context Variable" assertion be used in the "Apply XSL Transformation" assertion?

    Posted Jul 13, 2015 04:26 PM

    looking to use the value I set in a context variable "My New Service Name" in my XSL. Does anyone know the format of how to do this?

     

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:l7="http://ns.l7tech.com/2010/04/gateway-management"
      exclude-result-prefixes="xs"
      version="1.0">

    <xsl:template match="*">
    <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="/l7:Service/l7:ServiceDetail[1]/l7:Name[1]">
    <xsl:element name="l7:Name">My New Service Name</xsl:element>
    </xsl:template>
    <xsl:template match="/l7:Service/l7:ServiceDetail[1]/l7:ServiceMappings[1]/l7:HttpMapping[1]/l7:UrlPattern[1]">
    <xsl:element name="l7:UrlPattern">/my/new/url*</xsl:element>
    </xsl:template>

    </xsl:stylesheet>



  • 2.  Re: Can a variable set in "Set Context Variable" assertion be used in the "Apply XSL Transformation" assertion?

    Posted Jul 13, 2015 04:40 PM

    Hey James,

     

    You'll need to declare the variable as an xsl:param and reference it without 'curly braces' like so: $myVariable

     

    let me know if you need more information and i'll try to build something out a little later for you.

     

    thanks,

     

    Doyle



  • 3.  Re: Can a variable set in "Set Context Variable" assertion be used in the "Apply XSL Transformation" assertion?
    Best Answer

    Posted Jul 13, 2015 04:42 PM

    found this example i had

     

     

    <xsl:stylesheet version="1.0" xmlns:ver="http://www.multispeak.org/Version_3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

      <xsl:param name="UUID"/>

     

      <!-- Identity transform -->

      <xsl:template match="ver:ODEventNotification">

          <ver:ODEventNotification>

              <xsl:copy-of select="*"/>

               <ver:transactionID><xsl:value-of select="$UUID"/></ver:transactionID>

          </ver:ODEventNotification>

      </xsl:template>

      <xsl:template match="@*|*|processing-instruction()|comment()">

        <xsl:copy>

          <xsl:apply-templates select="*|@*|text()|processing-instruction()|comment()"/>

        </xsl:copy>

      </xsl:template>

    </xsl:stylesheet>

     



  • 4.  Re: Can a variable set in "Set Context Variable" assertion be used in the "Apply XSL Transformation" assertion?

    Posted Jul 13, 2015 04:46 PM

    That is correct. So the Context Variable in the Policy names UUID (its value) gets passed into the XSLT as that <xsl:param name="UUID">"you can even put a default value here</xsl:param>

     

    Then you use that xsl:param like you would in normal xsl via the $UUID syntax.

     

    You can also pass in variables with the "." notation like some of the prebuilt context variables like - ${request.http.header.myHeader} or ${myXPath.result}. Those would be

     

    <xsl:param name="request.http.header.myHeader"/>

    <xsl:param name="myXPath.result"/>

     

    You can obviously have multiple variables defined as well.



  • 5.  Re: Can a variable set in "Set Context Variable" assertion be used in the "Apply XSL Transformation" assertion?

    Posted Jul 14, 2015 10:00 AM

    Thanks Doyle/Andy! Exactly what I was looking for.