[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: selecting a parameter using string expression?

Subject: RE: selecting a parameter using string expression?
From: TSchutzerWeissmann@xxxxxxxxxxxxxxxx
Date: Wed, 14 Aug 2002 12:36:40 +0100
xsl variable substring before
Hi Mattias,

> > How about having only one parameter containing name:value pairs,
> > and make an adapted tokeniser to turn it into a node-set? That way
> > you could use XPath on your parameters to find out which ones they
> > are as well as what value they have.
> >
> > Just a suggestion - I haven't completely got my head round 
> your problem
> > so maybe I'm missing the wood for a tree or 2.
> > Tom
> 
> Well it sounds good, but how do you do an adapted tokenizer? 
> Must confess I
> haven't done that before :) Could you give an example?

well, if you wanted to do just use xslt you could try this. It's based on
Jeni's str.tokenize.template.xsl
(http://www.exslt.org/str/functions/tokenize/str.tokenize.template.xsl).

I'm not sure how quick it is though.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
  extension-element-prefixes="msxsl">

  <xsl:output method="html" encoding="utf-8"/>

  <xsl:param name="paras" select="/.."/>
  <!-- this is the raw list of parameters, a series
       of n : v pairs internally separated by ':' 
       and delimited by '#'s -->
  <!-- each pair will become a param element, 
       whose text value is v and whose name
       attribute is n -->
  

  <!-- turn paras into xml -->
     <xsl:variable name="convertParams">
       <xsl:call-template name="getParams">
        <xsl:with-param name="pList" select="$paras"/>
        <xsl:with-param name="delimiter" select="'#'"/>
        <xsl:with-param name="splitter" select="':'"/>
      </xsl:call-template>
    </xsl:variable>

    <!-- get a node-set of param elements -->
    <xsl:variable name="params" select="msxsl:node-set($convertParams)"/>
    
    <xsl:template name="getParams">
      <xsl:param name="pList" select="/.."/>
      <xsl:param name="delimiter" select="/.."/>
      <xsl:param name="splitter" select="/.."/>
      <xsl:choose>
        <xsl:when test="not($delimiter) or not($splitter)"/>
        <xsl:when test="contains($pList, $delimiter)">
          <xsl:if test="not(starts-with($pList, $delimiter))">
            <xsl:call-template name="getParams">
              <xsl:with-param name="pList" select="substring-before($pList,
$delimiter)" />
                <xsl:with-param name="delimiter" select="$delimiter"/>
                <xsl:with-param name="splitter" select="$splitter"/>
              </xsl:call-template>
            </xsl:if>
            <xsl:call-template name="getParams">
              <xsl:with-param name="pList" select="substring-after($pList,
$delimiter)" />
                <xsl:with-param name="delimiter" select="$delimiter"/>
                <xsl:with-param name="splitter" select="$splitter"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
              <param name="{substring-before($pList,$splitter)}">
                <xsl:value-of select="substring-after($pList,$splitter)"/>
              </param>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:template>
            
        <xsl:template match="/">
          <xsl:for-each select="$params/param">
            <p><xsl:value-of select="@name"/> is <xsl:value-of
select="."/></p>
          </xsl:for-each>
        </xsl:template>

      </xsl:stylesheet>

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.