lukazar Posted August 8, 2006 Share Posted August 8, 2006 HiI'm trying to calculate the length of a string. Take the length divide it by 60, which will give me how many substrings I'll need.so for example say I have this: <title> <para> This is a para in which things are being type for an example in which somthing is to be done.... </para></title> How would I use the fn:string-length()?I guess what I want to do would look kind of like this, however I don't think it'll work exatly the same in xslt.Heres kind of what it would look like in java int count = STRING.length();int num = count / 10;int start = 0;int end = 9;for(int i = 0; i < num; i++){ x[] = STRING.substring(start, end); start = end + 1; end = end + 10;} I think this is KIND of how it would look in xslt, minus the things I don't know :-/ <xsl variable name = string select = title/para/text() /><xsl variable name = start select = 0 /><xsl variable name = end select = 10 /><fn:string-length($string)> => store to some value called temp<!-- xslt code here --> => temp / 10 -> store to some value call num<choose> <!-- not sure if this will act like a for loop. I doubt it, so I'll probably need somthing else --> <when (some sort of seletion here not sure what)> <!-- this is where the while num != somthing --> <myXMLtag> <fn:substring($string,$start,$end/> <xsl: variable name = start select = $start + $end /> <xsl: variable name = end select = $end + 10 /> <xsl: variable name = somthing select = somthing + 1 /> </myXMLtag> </when></choose> I'm not sure if what I'm trying to do is even possible Any direction or insite would be much appricated. Link to comment Share on other sites More sharing options...
lukazar Posted August 8, 2006 Author Share Posted August 8, 2006 I've played with it a bit more and my xslt is starting to look like this... <xsl:param name = "start">1</xsl:param> <xsl:param name = "end">60</xsl:param> <xsl:param name = "ln">1</xsl:param> <xsl:template match="floordoc/bill/title" name="intro"> <xsl:variable name = "num" select="string-length(floordoc/bill/title/para/text())" /> <ttl> <line number='$ln'> <xsl:choose> <xsl:when test="$end > $num"> <xsl:value-of select="substring(floordoc/bill/title/para/text(),$start)"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="substring(floordoc/bill/title/para/text(),$start,60)"/> </xsl:otherwise> </xsl:choose> </line> <xsl:call-template name="intro"> <xsl:with-param name = "start" select='$start+60'/> <xsl:with-param name = "end" select='$end+60'/> <xsl:with-param name = "ln" select= '$ln+1'/> </xsl:call-template> </ttl> </xsl:template> Am I off in the right direction? Link to comment Share on other sites More sharing options...
lukazar Posted August 10, 2006 Author Share Posted August 10, 2006 I got it to work. Here is my final solution to the code <xsl:template match="title" name="intro"> <xsl:param name = "start" select="1" /> <xsl:param name = "end" select="60" /> <xsl:param name = "ln" select="1" /> <xsl:variable name="num" select="string-length(//floordoc/bill/title/para)" /> <xsl:choose> <xsl:when test="$end > $num"> <line number='{$ln}'> <xsl:value-of select="substring(//floordoc/bill/title/para,$start)"/> </line> </xsl:when> <xsl:otherwise> <line number='{$ln}'> <xsl:value-of select="substring(//floordoc/bill/title/para,$start,60)"/> </line> <xsl:call-template name="intro"> <xsl:with-param name = "start" select='$start+60'/> <xsl:with-param name = "end" select='$end+60'/> <xsl:with-param name = "ln" select= '$ln+1'/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now