Subject: RE: [xsl] Strings Position From: bryan.s.schnabel@xxxxxxxxxxxxxx Date: Tue, 25 Nov 2003 14:18:52 -0800 |
Hi Bruno, I may not have understood what you meant by shifting the string position by position. But here's a way of associating each character with its position. If this is way wrong, please let me know, and I'll try to better understand. This XML: <p Zahlen='00643cam 022002291 04500' /> When processed with this XSL: <xsl:template match="p"> <xsl:variable name="shorter"> <xsl:value-of select="substring-after(@Zahlen,substring(@Zahlen,1,1))" /> </xsl:variable> <P number="{@Zahlen}"> <xsl:element name="{concat('shift',string-length(@Zahlen))}"> <xsl:value-of select="substring(@Zahlen,1,1)"/> </xsl:element> <xsl:call-template name="short"> <xsl:with-param name="shortened" select="substring-after(@Zahlen,substring(@Zahlen,1,1))" /> </xsl:call-template> </P> </xsl:template> <xsl:template name="short"> <xsl:param name="shortened" /> <xsl:variable name="shorter"> <xsl:value-of select="substring-after($shortened,substring($shortened,1,1))" /> </xsl:variable> <xsl:element name="{concat('shift',string-length($shorter)+1)}"> <xsl:value-of select="substring($shortened,1,1)"/> </xsl:element> <xsl:if test="string-length($shorter) > 0"> <xsl:call-template name="short"> <xsl:with-param name="shortened" select="substring-after($shortened,substring($shortened,1,1))" /> </xsl:call-template> </xsl:if> </xsl:template> Gives you this result: <P number="00643cam 022002291 04500"> <shift24>0</shift24> <shift23>0</shift23> <shift22>6</shift22> <shift21>4</shift21> <shift20>3</shift20> <shift19>c</shift19> <shift18>a</shift18> <shift17>m</shift17> <shift16> </shift16> <shift15>0</shift15> <shift14>2</shift14> <shift13>2</shift13> <shift12>0</shift12> <shift11>0</shift11> <shift10>2</shift10> <shift9>2</shift9> <shift8>9</shift8> <shift7>1</shift7> <shift6> </shift6> <shift5>0</shift5> <shift4>4</shift4> <shift3>5</shift3> <shift2>0</shift2> <shift1>0</shift1> </P> Good luck, Bryan -----Original Message----- From: Bruno LLopes [mailto:brunollopes@xxxxxxx] Sent: Tuesday, November 25, 2003 1:33 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Strings Position Hi, I have a string for exemple '00643cam 022002291 04500' and I need look at every position of the string a see if each element has the correct value... How can I shift the string position by position? use xslt... thanks XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSL - using for-each with, Wendell Piez | Thread | RE: [xsl] XSL - using for-each with, Wickersty, Jeff |
Re: [xsl] XSL - using for-each with, Rick Taylor | Date | Re: [xsl] Dynamic Tables, J.Pietschmann |
Month |