This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Literal string question


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]