[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Literal string question

Subject: Re: Literal string question
From: Stuart Brown <stuart.brown@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 02 Jan 2002 11:27:33 +0000
select literal string
>
> What I have in mind is to PULL the data from a specific field in my
> XML document which has initials without a space between them.
>
> <CORPNAME>A.A. Peters</CORPNAME>
>

If all you want to do is select those elements whose string value
contains a dot followed by anything other than a space, would this
work?  Although doubtless it could be done more efficiently...

<xsl:template match="CORPNAME">
 <!-- Assign value to variable with whitespace normalized -->
 <xsl:variable name="x" select="normalize-space(.)"/>
 <xsl:choose>
  <!-- If it contains '.' proceed with recursive template -->
  <xsl:when test="contains($x, '.')">
   <xsl:call-template name="space-check">
    <!-- Recursive template uses param of everything after the first '.'

         The space is concatenated to the end to ensure that if the
         string ends with '.' this is not reported as an initial -->
    <xsl:with-param name="y" select="concat(substring-after($x, '.'),'
')"/>
   </xsl:call-template>
  </xsl:when>
  <!-- Otherwise return no initials -->
  <xsl:otherwise>
   <name initials="false"><xsl:value-of select="."/></name>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<xsl:template name="space-check">
 <xsl:param name="y"/>
 <xsl:choose>
  <!-- If the param starts with a space, then this particular dot was
not
       an initial. -->
  <xsl:when test="starts-with($y, ' ')">
   <xsl:choose>
    <!-- If there are more occurrences of '.' then repeat procedure -->
    <xsl:when test="contains($y, '.')">
     <xsl:call-template name="space-check">
      <xsl:with-param name="y" select="substring-after($y, '.')"/>
     </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
     <!-- No initials -->
     <name initials="false"><xsl:value-of select="."/></name>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:when>
  <xsl:otherwise>
   <!-- If the param does not start with a space, then the original
        string contained initials -->
   <name initials="true"><xsl:value-of select="."/></name>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.