This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: selecting a parameter using string expression?
- From: TSchutzerWeissmann at uk dot imshealth dot com
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 14 Aug 2002 12:36:40 +0100
- Subject: RE: [xsl] selecting a parameter using string expression?
- Reply-to: xsl-list at lists dot mulberrytech dot com
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