xsl-list
[Top] [All Lists]

RE: regexp question

2004-09-12 14:09:25
I would do it like this:

<xsl:template match="img[matches(@src, '.*dropcap/.\.gif')]" mode="dropcap">
  <xsl:value-of select="@alt"/>
</xsl:template>

<xsl:template match="xhtml:p">
  <xsl:variable name="temp">
    <xsl:apply-templates mode="dropcap"/>
  </xsl:variable>
    <p>
      <xsl:analyze-string flags="s" select="string($temp)" 
 regex='&quot;(.*?)&quot;'>
        <xsl:matching-substring>
        <q><xsl:value-of select="regex-group(1)"/></q>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
        <xsl:value-of select="."/>
        </xsl:non-matching-substring>
      </xsl:analyze-string>
    </p>
 </xsl:template>
 

Within paragraphs, there are just two things I want to do: 1) convert 
fake quotes to <q> elements, and b) to change graphic dropcaps like 
this ...

         <p><img 
src="http://graphics7.nytimes.com/images/dropcap/m.gif";
         width="37" height="33" align="left" border="0" 
alt="M" />OSCOW,
         ....</p>

.... to text. 

Also, is there some reasonably reliable way -- again using 
xslt 2.0 -- 
to take this ...

   <meta name="byl" content="By C. J. CHIVERS and STEVEN LEE MYERS" />

.... and turn it into this:

   <meta name="author" content="Chivers, C. J." />
   <meta name="author" content="Myers, Steven Lee" />


It all depends on how wide the variations are in your source data. If you
want to do the above, while also changing "BOB DU CHARME" to "du Charme,
Bob", then you have got an interesting challenge on your hands. Try to
define the algorithm you want to use before you start asking how to code it
in XSLT.

Michael Kay



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