2011-10-05 14 views
6

Il codice seguente funziona come previsto e quando Internet è presente nel testo viene abbinato.analyze-string non corrisponde quando regex è una variabile

<xsl:template name="IndexTerm"> 
    <xsl:param name="matchedRegex"> 
     <xsl:text>(.*)(Internet)(.*)</xsl:text> 
    </xsl:param> 
    <xsl:param name="text"></xsl:param> 
    <xsl:analyze-string select="$text" regex="(.*)(Internet)(.*)" flags="m"> 
     <xsl:matching-substring> 
      <xsl:call-template name="IndexTerm"> 
       <xsl:with-param name="text"> 
        <xsl:value-of select="regex-group(1)"></xsl:value-of> 
       </xsl:with-param> 
      </xsl:call-template> 
       <xsl:element name="a"> 
        <xsl:attribute name="id"> 
         <xsl:value-of select="generate-id($text)"></xsl:value-of> 
        </xsl:attribute> 
        <xsl:value-of select="regex-group(2)"></xsl:value-of> 
       </xsl:element> 
       <xsl:value-of select="regex-group(3)"></xsl:value-of> 
     </xsl:matching-substring> 
     <xsl:non-matching-substring> 
      <xsl:value-of select="."></xsl:value-of> 
     </xsl:non-matching-substring> 
    </xsl:analyze-string> 
</xsl:template> 

quando la linea:

<xsl:analyze-string select="$text" regex="(.*)(Internet)(.*)" flags="m"> 

è sostituito con:

<xsl:analyze-string select="$text" regex="$matchedRegex" flags="m"> 

essa non corrisponde più l'espressione regolare. Ho bisogno di passarlo come un parametro. C'è comunque da fare questo lavoro?

risposta

8

utilizzare un modello di valore di attributo

regex="{$matchedRegex}" 
Problemi correlati