xsl-list
[Top] [All Lists]

Re: [xsl] conditional xsl:analyze-string

2009-02-10 11:32:17
If I follow you, here (and I may not), you've provided the input, the
XSLT you're trying, and the output of the XSLT you're trying. It
would make answering questions a lot easier if you'd provide the
desired output in addition to or instead of the actual output. Even
better would be to also include a higher-level description of what
you're trying to do.


That said, maybe what you're looking for is <xsl:when>? (I say so in
part because I'd like to find out if this is a reasonable approach,
myself :-)

  <xsl:when test="matches(.,'[A-Z][a-z]+ [A-Z]\.')">
    <xsl:analyze-string select="." regex="([A-Z][a-z]+) ([A-Z]\.)">
      <xsl:matching-substring>
        <au>
          <s><xsl:value-of select="regex-group(1)"/></s>
          <f><xsl:value-of select="regex-group(2)"/></f>
        </au>
      </xsl:matching-substring>
    </xsl:analyze-string>
  </xsl:when>

(Just an example, not really intended to handle your data; would have
to be inside an <xsl:choose>, of course.


We have following kinds of data, which have totally unexpected
patterns. Can anyone suggest me the conditional way to write the
regular expression. It should not delete any kind of data if it is
not matching exactly. As we have seen below that some portion of
third name is getting deleted.

Input
<span class="name">Axxx B.</span>
<span class="name">B. Axxx</span>
<span class="name">xxx C. Dxxx</span>
<span class="name">Exxx-Exxx</span>

XSL
<xsl:analyze-string select="." 
regex="([A-Z][A-Z|a-z|\-|#]+)(,)?\s+([A-Z|\.]+)+">
<au>
  <xsl:matching-substring>
     <s><xsl:value-of select="regex-group(1)"/></s>
      <xsl:value-of select="regex-group(2)"/><xsl:text> </xsl:text>
     <f><xsl:value-of select="regex-group(3)"/></f>
  </xsl:matching-substring>
</au>
</xsl:analyze-string>
<xsl:analyze-string select="." 
regex="([A-Z|\.]+)(,)?\s+([A-Z][A-Z|a-z|\-|#]+)">
<au>
  <xsl:matching-substring>
   <f><xsl:value-of select="regex-group(1)"/></f>
   <xsl:value-of select="regex-group(2)"/><xsl:text> </xsl:text>
   <s><xsl:value-of select="regex-group(3)"/></s>
</xsl:matching-substring>
</au>
</xsl:analyze-string>

Output
<au><s>Axxx</s> <f>B.</f></au>
<au><f>B.</f> <s>Axxx</s></au>
<au><f>C.</f> <s>Dxxx</s></au> <!--xxx is deleted-->
<au/> <!-- text is deleted-->

Any clue in this regard will be highly appreciable!!!


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>