[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Find second character in a string (2)


Subject: Re: [xsl] Find second character in a string (2)
From: "Paulo Henrique S. Bermejo" <bermejo@xxxxxxxxxxx>
Date: Fri, 31 Aug 2001 18:28:40 -0300

`Very Good Tom.!!!

Thanks!
----- Original Message -----
From: Thomas B. Passin
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Sent: Friday, August 31, 2001 12:45 PM
Subject: Re: [xsl] Find second character in a string (2)


[Paulo Henrique S. Bermejo]

I'm using this below script:

<xsl:variable name="var-nome-preparado" select="'Clark Jenier Foz'"/>
<xsl:value-of
select="substring-before(substring-after(substring-after($var-nome-preparado
, ' '), ' '), ' ')"/>

And I only need to get the string "Clark Jenier".
If someone have a solution, advice me.

[Tom]

I believe from your other posts that you want to separate the last name from
the other names, and output the last name first, perhaps capitalised. Here
is a styesheet that returns the last name and the other names separately.

Example:

XML file: <name>First Middle Third Last</name>

Results:
<results>

 Last name:

 {Last }

 First names:

 {First Middle Third }

</results>

The stylesheet uses recursion to find the last space in the string of names,
and gets all text after that as the last name (of course, you last name
better not end with a space).  It will work for any number of names, not
just first and last.

To get the other names, it gets the substring-before() the last name.

You could use these templates to re-order the names, to capitalize them, and
do other manipulations.

Cheers,

Tom P

Here's the stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding='utf-8'/>

<!--========= Driver template ======-->
<xsl:template match="/name">
<results>
 Last name:
     {<xsl:call-template name='getLastName'>
          <xsl:with-param name='string' select='text()'/>
     </xsl:call-template> }

 First names:
     {<xsl:call-template name='getFirstNames'>
          <xsl:with-param name='string' select='text()'/>
     </xsl:call-template>}
</results>
</xsl:template>

<!--======= Extract the last name ====-->
<xsl:template name='getLastName'>
    <xsl:param name='string'/>
     <xsl:variable name='notDoneYet' select='contains($string," ")'/>
     <xsl:choose>
          <xsl:when test='$notDoneYet'>
               <xsl:call-template name='getLastName'>
                    <xsl:with-param name='string'
select='substring-after($string," ")'/>
               </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
               <xsl:value-of select='$string'/>
          </xsl:otherwise>
     </xsl:choose>
</xsl:template>

<!--=== Extract the non-last names ====-->
<xsl:template name='getFirstNames'>
     <xsl:param name='string'/>
     <xsl:variable name='lastName'><xsl:call-template name='getLastName'>
      <xsl:with-param name='string' select='text()'/>
          </xsl:call-template></xsl:variable>
     <xsl:value-of select='substring-before($string,$lastName)'/>
</xsl:template>

</xsl:stylesheet>





 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
Keywords
xml