xsl-list
[Top] [All Lists]

Re: [xsl] XML attribute value to pattern match of the replace function

2010-02-20 09:55:09
Selvaganesh wrote:
Dear Team,

How can I assign the attribute value to pattern of the replace function,
kindly guide me.

Input XML:
<caseref party1="Drury" party2="Secretary of State for the Environment, Food
and Rural Affairs">Drury v Secretary of State for the Environment, Food and
Rural Affairs [2004] EWCA Civ 200; [2004] 1 W.L.R. 1906 </caseref>

XSL:
<hov:template match="caseref">
<hov:element name="caseref"><hov:value-of select="replace(.,
'(@party1(_dot_)*?(_at_)party2)', 
'&lt;cite&gt;$1&lt;/cite&gt;')"/></hov:element>
</hov:template>

You need to concat the attribute values e.g.
select="replace(., concat('(', @party1, '.*?', @party2, ')'), '&lt;cite&gt;$1&lt;/cite&gt;')"

But the replacement looks as if you want to insert a 'cite' element so using analyze-string instead of replace might be what you really want. So instead of the value-of use e.g.

  <hov:analyze-string select="." regex="({(_at_)party1}(_dot_)*?{@party2})">
    <hov:matching-substring>
       <cite>
         <xsl:value-of select="regex-group(1)"/>
       </cite>
    </hov:matching-substring>
    <hov:non-matching-substring>
       <xsl:value-of select="."/>
    </hov:non-matching-substring>
  </hov:analyze-string>

The above is untested.


--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

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