|
Subject: Re: [xsl] How to substitute a string based on number From: Joerg Pietschmann <joerg.pietschmann@xxxxxx> Date: Mon, 29 Oct 2001 17:45:58 +0100 |
Hi Deep,
Mailer Mailer <maillistboxes@xxxxxxxxx> 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
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] XSL-Fo and CSS, Joshua . Kuswadi | Thread | Re: [xsl] How to substitute a strin, Mailer Mailer |
| [xsl] XSL-Fo and CSS, Boell, Dieter | Date | [xsl] FO/FOP Query - Numbered List, Joerg Pietschmann |
| Month |