[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: Re: [xsl] XML attribute value to pattern match of the replace function
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Sat, 20 Feb 2010 16:54:44 +0100

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.*?@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="({@party1}.*?{@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/


Current Thread