xsl-list
[Top] [All Lists]

Re: [xsl] Searching text with elements help needed

2010-06-18 02:44:45
Russ,

Without having looked at your solution, how about this (in addition to the 
usual identity templates):

<xsl:variable name="prefix" select="'For more information see '"/>

<xsl:template match="Para[CrossReference]">
  <xsl:copy>
    <xsl:for-each select="node()">
      <xsl:choose>
        <xsl:when test="self::CrossReference and 
preceding-sibling::node()[1][self::text() and matches(., concat($prefix, 
'$'))]">
          <xsl:comment select="'drop CrossReference'"/>
        </xsl:when>
        <xsl:when test="self::text() and matches(., concat($prefix, '$'))">
          <xsl:value-of select="substring-before(., $prefix)"/>
          <xsl:comment select="concat('drop ', $prefix)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="."/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </xsl:copy>
</xsl:template>

- Michael

Am 18.06.2010 um 01:46 schrieb Russell Urquhart:

I have been tasked with trying to find a sentence in a <Para> element similar 
to the following:

<Para>
Some text...For more information see 
<CrossReference>ItemofInterest</CrossReference>. Some more text, etc.
</Para>

I have to determine if a sentence of the "For more information see 
<CrossReference> </CrossReference>." and, ideally delete it, but i would be 
just as happy to put it in comments.

I was trying the following in a template:

<xsl:template match="CrossReference">                                         
                 
 ***CROSSREFERENCE_FOUND***                                                   
                 
  <xsl:apply-templates/>                                                      
                 
</xsl:template>                                                               
                 
<xsl:template match="Para">                                                   
                 
 <P>                                                                          
                 
<!--      <xsl:analyze-string select="." regex="For more                      
                  
+information[^\*]*\*\*\*CROSSREFERENCE_FOUND\*\*\*[^\.\?!]*[\.\?!]"> -->      
                  
     <xsl:analyze-string select="." regex="(For more 
information[^\.\?!]*[\.\?!])">            

       <xsl:matching-substring>                                               
                 
          <xsl:value-of select="concat('Found', regex-group(1), 'Found end')" 
/>               

       </xsl:matching-substring>                                              
                 
     </xsl:analyze-string>                                                    
                 
  <xsl:apply-templates/>                                                      
                 
 </P>                                                                         
                 
</xsl:template>  

Regular <Para> elements are translated to html <P> elements. I had tried to 
convert the <CrossReference> element to text thinking that would help the 
search process, but no dice.

Can someone shed some light on how i should approach this and or have an 
example to share!

Thanks for any help!

Russ

--
_______________________________________________________________
Michael Müller-Hillebrand: Dokumentations-Technologie
Adobe Certified Expert, FrameMaker
Lösungen und Training, FrameScript, XML/XSL, Unicode
Blog: http://cap-studio.de/ - Tel. +49 (9131) 28747






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