Re: using p:variable

Dave,

On 14 Dec 2008, at 10:20, Dave Pawson wrote:
> I've declared a variable, first child of a pipeline
>
> How can I obtain the value of that for direct inclusion
> within the pipeline result port please?

Variables hold strings. The result of a pipeline is an XML document.  
So you can't output the variable directly, but you can use it to  
create the value of an element or attribute by passing it in as the  
value of an option or parameter.

For example, if you wanted to pass its value into an XSLT step as a  
parameter to the XSLT, you could do:

<p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   exclude-inline-prefixes="xsl">

   <p:variable name="product-name" select="'Fribble Widgets'" />

   <p:xslt>
     <p:input port="source"><p:inline><product /></p:inline></p:input>
     <p:with-param name="product-name" select="$product-name" />
     <p:input port="stylesheet">
       <p:inline>
         <xsl:stylesheet version="1.0">
           <xsl:param name="product-name" />
           <xsl:template match="product">
             <product><xsl:value-of select="$product-name"/></product>
           </xsl:template>
         </xsl:stylesheet>
       </p:inline>
     </p:input>
   </p:xslt>

</p:pipeline>

Or if you want to pass it as the value of an option, you could do  
something along the lines:

<p:pipeline xmlns:p="http://www.w3.org/ns/xproc">

   <p:variable name="product-name" select="'Fribble Widgets'" />

   <p:add-attribute match="product" attribute-name="name">
     <p:input port="source"><p:inline><product /></p:inline></p:input>
     <p:with-option name="attribute-value" select="$product-name" />
   </p:add-attribute>

</p:pipeline>

Cheers,

Jeni
-- 
Jeni Tennison
http://www.jenitennison.com

Received on Sunday, 14 December 2008 11:13:26 UTC