This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Create a node set and then apply a template to it
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Sat, 27 Apr 2002 06:40:39 -0700 (PDT)
- Subject: [xsl] Re: Create a node set and then apply a template to it
- Reply-to: xsl-list at lists dot mulberrytech dot com
> I'm just looking into using XSLT (translation: clueless) for a
> project I'm working on, and I'm wondering if it's possible to create
> a node set via a template and then apply some other template to it?
> Since I don't have all of the terminology down yet, let me illustrate
> via an example.
>
> Given the text node, "out of luck", I'd like to end up with the node
> set containing the following elements:
>
> <WORD>out</WORD>
> <WORD>of</WORD>
> <WORD>luck</WORD>
>
> and to that node set I'd like to apply a template. Looking around it
> seems as if a lot of people have had a similar sort of question, but
> (in my current state of ignorance) I've been unable to directly apply
> their concerns to my problem.
>
> Any help or pointers to documentation would be most appreciated.
>
Hi Paul,
You can tokenize the text using the str-split-to-words template from
FXSL.
If you capture the result into a xsl:variable, then convert it from an
RTF to a node-set, then you'd be able to apply other templates on this
node-set. In your concrete case this stylesheet:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:vendor="urn:schemas-microsoft-com:xslt"
>
<xsl:import href="strSplit-to-Words.xsl"/>
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:variable name="vwordNodes">
<xsl:call-template name="str-split-to-words">
<xsl:with-param name="pStr" select="/"/>
<xsl:with-param name="pDelimiters"
select="', 	 '"/>
</xsl:call-template>
</xsl:variable>
<xsl:apply-templates select="vendor:node-set($vwordNodes)/*"/>
</xsl:template>
<xsl:template match="word">
<xsl:value-of select="concat(position(), ' ', ., ' ')"/>
</xsl:template>
</xsl:stylesheet>
when applied on this source xml document:
<t>out of luck</t>
will produce this result:
1 out
2 of
3 luck
Hope this helped.
Cheers,
Dimitre Novatchev.
__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list