xsl-list
[Top] [All Lists]

Re: [xsl] parametrized return values in recursive functions?

2009-04-05 10:46:44
Supposing, we have following input XML:

<conf>
  <value>--name httpd</value>
  <args1>acd anadrom bcd cccd ddr gcd httpd iscsi xine</args1>
</conf>

The stylesheet for the problem you described will be:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                       xmlns:str="http://exslt.org/strings";
                       exclude-result-prefixes="str"
                       version="1.0">

   <xsl:output method="html" indent="yes" />

   <xsl:template match="conf">
     <html>
       <head>
         <title/>
       </head>
       <body>
         <xsl:variable name="sel" select="str:tokenize(value, ' ')[2]" />
         <form action="someaction">
           <select name="x">
             <xsl:for-each select="str:tokenize(args1, ' ')">
               <xsl:choose>
                 <xsl:when test=". = $sel">
                   <option value="{.}"
selected="selected"><xsl:value-of select="." /></option>
                 </xsl:when>
                 <xsl:otherwise>
                   <option value="{.}"><xsl:value-of select="." /></option>
                 </xsl:otherwise>
               </xsl:choose>
             </xsl:for-each>
           </select>
         </form>
       </body>
     </html>
   </xsl:template>

</xsl:stylesheet>

I do not have the Perl:libXSLT processor with me. I tested the above
stylesheet with Xalan and the  EXSLT tokenize extension.

Please check if Perl:libXSLT supports this extension function.
Otherwise, you can write it yourself as a callable named template.

On Sun, Apr 5, 2009 at 4:40 PM, himanshu padmanabhi
<himanshu(_dot_)padmanabhi(_at_)gmail(_dot_)com> wrote:
Extremely sorry.here it is.

input

[ both are space separated,so I need to first tokenize '$value' to get 
'httpd',
then tokenize '$args1' to display other elements(excluding httpd) ]
  $value = --name httpd
  $args1 = acd anadrom bcd cccd ddr gcd httpd iscsi .... xine

Output

  'httpd' as the selected element in combo and other elements from '$args1'.

I am using XSLT 1.0 and XSLT processor as Perl:libXSLT.

Thanks and Regards,
Himanshu Padmanabhi.



-- 
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>