How to inline argument passed to xrl2 in its template

Poster Content
nk4um Moderator
Posts: 485
August 27, 2010 16:30Variant 2 is the closest
Hi Mircea,

Variant 2 is the way to go. xrl:eval is the correct operation because it sets a string value into the xml document, xrl:include inserts an xml fragment into the document.

However there are two mistakes in your variant2:

1) xrl:eval attempts to source the specified request. Your argument month-number cannot be sourced because it is not an identifier to a resource, instead it is just a string. To fix this you can change your mapper to convert the argument it a pass-by-value string like this:

      <request>
         <identifier>active:xrl2</identifier>
         <argument name="template">xrl:template</argument>
         <argument name="content">xrl:content</argument>
         <argument name="month-number" method="as-string">arg:month-number</argument>
      </request>

For more details of the method attribute on declarative requests see:
http://docs.netkernel.org/book/view/book:guide:logicalreference/doc:logicalreference:module:standard:logical:declarative:request:syntax

2) When xrl process a document all xrl namespace tags are removed from the document as they are processed. What this means is that the xpath of "." will no longer be there and so cannot be substituted.

Try this:

<html xmlns:xrl="http://netkernel.org/xrl">
   <body>
      <h1>Monthly expenses</h1>
      <xrl:eval>
         <xrl:xpath>../h1</xrl:xpath>
         <xrl:identifier>arg:month-number</xrl:identifier>
      </xrl:eval>
      <xrl:include identifier="arg:content"/>
   </body>
</html>

Cheers, Tony
nk4um User
Posts: 26
August 25, 2010 15:54How to inline argument passed to xrl2 in its template
Hi,

I''m trying to inline an argument passed to xrl2 in its template.

I start with this external request:

http://localhost:8080/expenses/month/7


In the mapper''s configuration I have the following endpoints:

   <endpoint>
      <id>expensesByMonth</id>
      <grammar>res:/expenses
         <optional>/month/
            <group name="month-number">
               <regex type="integer"/>
            </group>
         </optional>
      </grammar>
      <request>
         <identifier>active:xrl2</identifier>
         <argument name="template">xrl:template</argument>
         <argument name="content">xrl:content</argument>
         <argument name="month-number">arg:month-number</argument>
      </request>
      <header name="mime">text/html</header>
   </endpoint>
   <endpoint>
      <id>monthly-expenses-template</id>
      <grammar>xrl:template</grammar>
      <request>
         <identifier>res:/resources/xrl/template.xml</identifier>
      </request>
   </endpoint>
   <endpoint>
      <id>monthly-expenses-content</id>
      <grammar>xrl:content</grammar>
      <request>
         <identifier>res:/resources/xrl/content.xml</identifier>
      </request>
   </endpoint>


I played with the following template variants. None of them works.

variant 1
<html xmlns:xrl="http://netkernel.org/xrl">
   <body>
      <h1>Monthly expenses <xrl:eval><xrl:identifier>arg:month-number</xrl:identifier></xrl:eval></h1>
      <xrl:include identifier="arg:content"/>
   </body>
</html>


variant 2
<html xmlns:xrl="http://netkernel.org/xrl">
   <body>
      <h1>Monthly expenses</h1>
      <xrl:eval>
         <xrl:xpath>.</xrl:xpath>
         <xrl:identifier>arg:month-number</xrl:identifier>
      </xrl:eval>
      <xrl:include identifier="arg:content"/>
   </body>
</html>


variant 3
<html xmlns:xrl="http://netkernel.org/xrl">
   <body>
      <h1>Monthly expenses [[arg:month-number]]</h1>
      <xrl:include identifier="arg:content"/>
   </body>
</html>


Note: Tony already said in a previous post answer that the syntax [[arg:month-number]] is not supported anymore in xrl2.

How should I do it?

Thanks,
Mircea