- From: Stephen Clarke <any@longusername.worldonline.co.uk>
- Date: Thu, 21 Mar 2002 13:16:33 -0000
- To: "Brenda Bell" <bbell@juicesoftware.com>, <www-xsl-fo@w3.org>
OK. Here's what i'm thinking. Do a recursion of [ substring-after, followed by substring-before for the after bit. ] Start with the null string, ie, the substring-after null is the whole original string, umm, or something. $delims = $delims - 1; if $delims *recurse* <info (num) = substring-before( substring-after( ., substring( $delims, 1, 2 ) ) ) <xsl:call-template name="self"/> <xsl:call-template name="splitString"> <xsl:param name="delims">;;:;,::,.;</xsl:param> <xsl:param name="elementNames">one:two:three:four:five:six:eight:nine:ten:eleven</xsl:p aram> <xsl:param name="string"><xsl:value-of select="packedInfo"/></xsl:param> <xsl:param name="delims"/> <xsl:param name="elementNames"/> <xsl:param name="string"/> <xsl:if test="$string"/> <xsl:element name="substring-before( $elementNames, ':')"> <xsl:value-of select="substring-before( $string, substring( $delims, 1, 2 ) )"/> </xsl:element> <xsl:call-template name="self"> <xsl:param name="delims"><xsl:value-of select="substring( $delims, 2 )"/></xsl:param> <xsl:param name="elementNames"><xsl:value-of elect="substring-after( $elementNames, ':')"/></xsl:param> <xsl:param name="string"><xsl:value-of select="substring-after( $string, substring( $delims, 1, 2 ) )"/> </xsl:call-template> </xsl:if> Sorry. I ran out of time. That's it. Maybe it will stimulate some ideas. The indentation gets all messed up in emails, but if you cut and paste and reconstitute ... -- Best, S. ----- Original Message ----- From: "Brenda Bell" <bbell@juicesoftware.com> To: <www-xsl-fo@w3.org> Sent: Wednesday, March 20, 2002 6:26 PM Subject: RE: Splitting a stirng > I did something similar which works. My problem is that the original string > has 11 items... so I have to do this 11 times. The first one is easy, but > the second iteration really needs to eliminate the "used-up" part of the > string before it does another substring-before. I'm using variables and > doing it manually line by line, so it's very ugly. > > -----Original Message----- > From: Stephen Clarke [mailto:any@longusername.worldonline.co.uk] > Sent: Wednesday, March 20, 2002 1:18 PM > To: Brenda Bell; www-xsl-fo@w3.org > Subject: Re: Splitting a stirng > > > Hi Brenda, > > ----- Original Message ----- > From: "Brenda Bell" <bbell@juicesoftware.com> > To: <www-xsl-fo@w3.org> > Sent: Wednesday, March 20, 2002 4:02 PM > Subject: Splitting a stirng > > > > I have an XML document with an element whose content is a string > containing > > "fields" delimited by semi-colons. Example: > > > > <PACKEDINFO>123;ABC;0;X</PACKEDINFO> > > > > I want to transform this element into something that looks like this: > > > > <UNPACKEDINFO> > > <INFO1>123</INFO1> > > <INFO2>ABC</INFO2> > > <INFO3>0</INFO3> > > <INFO4>X</INFO4> > > </UNPACKEDINFO> > > > > Can I do this with XSL? I'm familiar with the substring functions and > while > > I've never used them, I've read the documentation on the param and > variable > > elements. > > > > If I were doing this in a programming language like VB, I'd set a variable > > to the contents of <PACKEDINFO>, pop off the part before the first > > semi-colon, create my new element and remove the text up to and including > > the first semi-colon from the string setting me up for my next iteration. > > > > Any comments on how I can do this with XSL would be greatly appreciated. > I > > guess my biggest question is whether I should use a param or variable -- > I'm > > having difficulty distinguishing between them -- and whether I can change > a > > param or variable's value by simply declaring it again. I'm very > confused. > > > > > > > > funny , i was just reading about substring today. > > maybe this will give you some clue. Have you tried anything like this? > > > 123 = substring-before( /top/node, ";" ) > ABC = substring-before( substring-after( /top/padkedinfo, ";" ), ";" ) > > eg. > <unpackedinfo> > <info1><xsl:value-of select="substring-before( /top/packedinfo, > ';' )"/><info1> > > ... > > could be wrong i'm just a beginner. > -- > Best, > Steve >
Received on Thursday, 21 March 2002 08:16:37 UTC