Iterate trough a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jurrie

    #1

    Iterate trough a string

    hi all,

    In my XML document i have <paragraph type="...">some text</paragraph>
    the type="..." specifies what type the paragraph is. This is all
    defined somewehere else in the document.
    The type specifies what font should be used, if the text should be
    bold etc.
    It also specifies if the text should be underlined including spaces,
    underlined excluding spaces or not underlined at all.
    The problem arise when i need to underline excluding the spaces
    (space, tab etc.)
    To do this i have to itterate trough the string and use underscore if
    the character is not a whitespace. I have this in my xsl document:
    ===code======== =============== =============== =============== =============== =====
    <xsl:template name="word_unde rline">
    <xsl:param name="pos" />
    <xsl:choose>
    <xsl:when test="substring (current()/text(),$pos,$po s)=' '">
    <fo:inline text-decoration="no-underline">
    <xsl:value-of select="substri ng(current()/text(),$pos,$po s)" />
    </fo:inline>
    </xsl:when>
    <xsl:otherwis e>
    <fo:inline text-decoration="und erline">
    <xsl:value-of select="substri ng(current()/text(),$pos,$po s)" />
    </fo:inline>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="string-length()!=$pos" >
    <xsl:call-template name="word_unde rline">
    <xsl:with-param name="pos">
    <xsl:value-of select="$pos+1" />
    </xsl:with-param>
    </xsl:call-template>
    </xsl:if>
    </xsl:template>
    ===/code=========== =============== =============== =============== =============== =

    and then i call this template like this:

    ===code======== =============== =============== =============== =============== =====
    <xsl:when test="/document/definitions/stylesheets/stylesheet[@name=current()/@stylesheet]/character/face/wordunderline=' 1'">
    <xsl:call-template name="word_unde rline">
    <xsl:with-param name="pos">1</xsl:with-param>
    </xsl:call-template>
    </xsl:when>
    ===/code=========== =============== =============== =============== =============== =

    If I run the above throug FOP (with xalan-j) the text looks all messed
    up. If the string is <paragraph type="...">some text</paragraph> the
    output looks something like this:
    soos mesome t somet tex mtxt ext
    or something like that. and everything is underlined. (spaces also)

    Does anybody know what i am doing wrong?
    thanks for any help,
    Jurrie
Working...