[oXygen-user] Re: The last problems
George Cristian Bina
Thu Nov 13 02:14:15 CST 2003
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