This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: How to substitute a string based on number
- To: XSL List <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl] How to substitute a string based on number
- From: Joerg Pietschmann <joerg dot pietschmann at zkb dot ch>
- Date: Mon, 29 Oct 2001 17:45:58 +0100
- Organization: ZKB
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Deep,
Mailer Mailer <maillistboxes@yahoo.com> wrote:
> How can I substitute a string based on a number, e.g.
>
> 1 --- Jaunary
> 2 --- February
[...]
> In wrox book an implementation is given but it seems
> to be MS specific. The implementation is
[...]
> <xsl:variable name="monthnames"
> select="msxml:node-set($monthnames.tf)"/>
It is MSXML specific but only slightly. Other processors
have a similar extension function node-set(), look it
up in the procesor specific dokumentation.
Depending on the problem you want to solve, you probably
don't need this extension function. Try the following style
sheet:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:data="uri:some.uri.you.control"
exclude-result-prefixes="data">
<data:monthnames.tf>
<mnth name="January"/>
<mnth name="February"/>
<mnth name="March"/>
<!-- snip, to keep the example short -->
</data:monthnames.tf>
<xsl:template match="month">
<xsl:value-of select="document('')/*/data:monthnames.tf/*[number()]/@name">
</xsl:template>
<xsl:template match="node()"/>
</xsl:stylesheet>
This should output the name of the month for each month element
in your source XML which has a month number as its content. Well,
at least if you complete the monthnames array properly. The technique
is based on the fact that elements with a non-XSLT namespace are
allowed in style sheets (http://www.w3.org/TR/xslt.html#stylesheet-element,
last paragraph), and that document('') reads the stylesheet itself.
The "exclude-result-prefixes" ensures that the data namespace is
not copied through into the output.
HTH
J.Pietschmann
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list