Subject: Re: How to substitute a string based on number
From: Johannes Döbler <jd@xxxxxxxxxxxxxx>
Date: Mon, 29 Oct 2001 14:18:00 +0100
|
msxml:node-set is a extension function and not a standard function. It
converts a result tree fragment into a nodeset. Different XSLT-processors
have different extension for this function, (if they need it at all).
A standard solution would be:
Create a file monthnames.xml:
--------------------------------------------
<monthnames>
<month>January</month>
<month>February</month>
<month>March</month>
<month>April</month>
<month>May</month>
<month>June</month>
<month>July</month>
<month>August</month>
<month>September</month>
<month>October</month>
<month>November</month>
<month>December</month>
</monthnames>
--------------------------------------------
and then your stylesheet could look like:
--------------------------------------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:variable name="monthnames"
select="document('monthnames.xml')/monthnames/month/text()"/>
<xsl:param name="month" select="1"/>
<xsl:template match="/">
<test>
<xsl:value-of select="$monthnames[$month]"/>
</test>
</xsl:template>
</xsl:stylesheet>
--------------------------------------------
Cheers,
Johannes
At 04:37 29.10.2001 -0800, you wrote:
Hello All,
How can I substitute a string based on a number, e.g.
1 --- Jaunary
2 --- February
.....
11 November
12 --- December
In wrox book an implementation is given but it seems
to be MS specific. The implementation is
-----------------
<xsl:variable name="monthnames.tf">
<mnth name="January"/>
<mnth name="February"/>
<mnth name="March"/>
<mnth name="April"/>
<mnth name="May"/>
<mnth name="June"/>
<mnth name="July"/>
<mnth name="August"/>
<mnth name="September"/>
<mnth name="October"/>
<mnth name="November"/>
<mnth name="December"/>
</xsl:variable>
<xsl:variable name="monthnames"
select="msxml:node-set($monthnames.tf)"/>
....
...
<xsl:value-of select="$monthnames/*[$month]/@name"/>
In this way monthnames variable works as an array.
Is there such kinda standard way to access the
variable ... do not mention xslt processor specific
stuff. Is node-set a standard function?
Any pointers may help.
Thanks
Deep
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
- Re: Case conversion in XSL?, (continued)
- Wendell Piez - Thu, 18 Oct 2001 12:51:03 -0400 (EDT)
- Thomas Holz - Mon, 29 Oct 2001 03:53:12 -0500 (EST)
- Mailer Mailer - Mon, 29 Oct 2001 07:47:20 -0500 (EST)
- Goetz Bock - Mon, 29 Oct 2001 08:04:57 -0500 (EST)
- Johannes Döbler - Mon, 29 Oct 2001 08:28:07 -0500 (EST) <=
- Michael Kay - Mon, 29 Oct 2001 08:42:59 -0500 (EST)
- Jeni Tennison - Thu, 18 Oct 2001 06:12:55 -0400 (EDT)
- Michael Kay - Thu, 18 Oct 2001 06:45:52 -0400 (EDT)
- David Carlisle - Thu, 18 Oct 2001 06:46:48 -0400 (EDT)
|
|