[oXygen-user] curiosity sake

Aga Shirazi
Fri Nov 14 12:33:15 CST 2003


George,

Just for curiosity sake,

In problem #2, we know that there are digits at the end to be removed, but 
what if digits and alphabets are mixed? Ex:

XML FILE
<INFO>some book 19 some discription</INFO>
<INFO>another book 2000 some description again</INFO>
<INFO>the last book 90 text</INFO>

Now, we need just the text before the number. i.e. "some book" or "another 
book".

Thanks
Aga Shirazi



**********************************************************************
You wrote:



Hi Aga,

> FIRST:
> In this problem, I just need the last four digits of the ISBN. But the
> catch is that the ISBN length is not constant, but is always greater than
4.
>
>
> XML FILE
> <ISBN>23fds783222s</ISBN>
> <ISBN>f2h123as</ISBN>
> <ISBN>2hgfhhgf3432h123asssz</ISBN>

If you want the last for characters from a string you can use something
like:
<xsl:variable name="value" select="."/>
<xsl:value-of select="substring($value, string-length($value)-3)"/>
If you want to remove eventual characters before getting the last 4
characters you can select the value as below:
<xsl:variable name="value" select="translate(., 'abcde....', '')"/>

>
> SECOND:
> I have no idea how to go about this one. I just have to select the text
> before the number. Do you have any idea?
>
> XML FILE
> <INFO>hotmail 1990</INFO>
> <INFO>some text here 2000</INFO>
> <INFO>some more text gere 9092</INFO>

If you know you have a 4 digit number then you can use substring to get it:
<xsl:value-of select="substring($value, 1, string-length($value)-4)"/>

If you know that the text does not contain numbers you can use translate to
remove the digits:
<xsl:value-of select="translate($value, '0123456789', '')"/>

otherwise you can use a template to remove digits from the end:

    <xsl:template name="selectBeforeNumber">
      <xsl:param name="value" select="''"/>
      <xsl:variable name="c" select="substring($value,
string-length($value))"/>
      <xsl:choose>
        <xsl:when test="$c='0' or $c='1' or $c='2' or $c='3' or $c='4' or
$c='5' or $c='6' or $c='7' or $c='8' or $c='9'">
          <xsl:call-template name="selectBeforeNumber">
            <xsl:with-param name="value" select="substring($value, 1,
string-length($value)-1)"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$value"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

and call it like below if the current selection is an INFO node:

<xsl:call-template name="selectBeforeNumber">
  <xsl:with-param name="value" select="."/>
</xsl:call-template>

Regards,
 George







More information about the oXygen-user mailing list