Subject: Re: [xsl] Q - Parsing & Manipulating Strings from XSL From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Mon, 30 May 2005 06:00:59 +1000 |
> Furthermore, in the same repsonse, I have a string of the format > YYYYNYY [chars may be either Y or N], also respresented as a free > format string. This represents the days of the week starting from > Sunday... Now I need to take each char, and replace it with a <TD > color="green">S</TD> if it is Y, and <TD>S</TD> if it is N. > > Anyway I can do that in XSL ? One can use the str-map template/function of FXSL. In XSLT 2.0 one would write something like this: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="http://fxsl.sf.net/" xmlns:testmap="f:testmap" exclude-result-prefixes="f xs testmap" > <xsl:import href="../f/func-str-map.xsl"/> <xsl:output omit-xml-declaration="yes" indent="yes"/> <!-- to be applied on any xml source --> <xsl:variable name="vFunMap" as="element()"> <testmap:testmap/> </xsl:variable> <xsl:template match="/"> <xsl:sequence select="f:str-map($vFunMap, 'YYYYNYY')"/> </xsl:template> <xsl:template name="wrapChars" match="testmap:*" mode="f:FXSL"> <xsl:param name="arg1"/> <TD> <xsl:if test="$arg1 = 'Y'"> <xsl:attribute name="color">green</xsl:attribute> </xsl:if> <xsl:text>S</xsl:text> </TD> </xsl:template> </xsl:stylesheet> This approach has the advantage that f:str-map($vFunMap, 'YYYYNYY') can be part of an XPath expression. Cheers, Dimitre Novatchev. On 5/29/05, Ahsan Ali <doubleletter@xxxxxxxxx> wrote: > Hi, > > I'm working on a (airline related) project in which I have following dilemma: > > A soap response contains a complex hierarchy of data, in which, if > the departure time is 00:45 hours then it is represented as 45 ! To > make matters worse, the schema defines it as a string. I have no > influence over the schema since I'm querying a webservice. So I need > to pad that 45 with 0s and of course add that colon. Is there a way I > can do that in XSL ? > > Furthermore, in the same repsonse, I have a string of the format > YYYYNYY [chars may be either Y or N], also respresented as a free > format string. This represents the days of the week starting from > Sunday... Now I need to take each char, and replace it with a <TD > color="green">S</TD> if it is Y, and <TD>S</TD> if it is N. > > Anyway I can do that in XSL ? > > My current solution is to access the above fields from the asp page, > and manipulate it in VBScript ! This is ugly and expensive as I need > to make a query for every _type_ of task... > > Any help is appreciated.... > > Best Regards, > > Ahsan
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Q - Parsing & Manipulatin, Michael Kay | Thread | Re: [xsl] Q - Parsing & Manipulatin, Ahsan Ali |
[xsl] Merging arbitrary XML files, Frans Englich | Date | RE: [xsl] Print all root node attri, Michael Kay |
Month |