title: XSLT string manipulation
body: <p>Could someone tell me the easiest way to fix below ? I currently have a file containing a variety of ways to define cross references (basically links to other pages), and I want to convert 2 of them to a single format. Below XML is a simplified sample showing source format :</p>
  
  <pre><code>&lt;Paras&gt;
  &lt;Para tag="CorrectTag"&gt;
  &lt;local xml:lang="en"&gt;Look at this section  &lt;XRef XRefType="(page xx)"&gt;(page 36)&lt;/XRef&gt; for more information&lt;/local&gt;
  &lt;/Para&gt;
  &lt;Para tag="InCorrectTag"&gt;
  &lt;local xml:lang="en"&gt;Look at some other section (page &lt;XRef XRefType="xx"&gt;52&lt;/XRef&gt;) for more information&lt;/local&gt;
  &lt;/Para&gt;
  &lt;/Paras&gt;
  </code></pre>
  
  <p>What I want to achieve is the following :</p>
  
  <pre><code>&lt;Paras&gt;
  &lt;Para tag="CorrectTag"&gt;
      &lt;local xml:lang="en"&gt;Look at this section &lt;XRef XRefType="(page xx)" XRefPage="36"/&gt; for more information&lt;/local&gt;
  &lt;/Para&gt;
  &lt;Para tag="InCorrectTag"&gt;
      &lt;local xml:lang="en"&gt;Look at some other section &lt;XRef XRefType="(page xx)" XRefPage="52"/&gt; for more information&lt;/local&gt;
  &lt;/Para&gt;
  &lt;/Paras&gt;
  </code></pre>
  
  <p>Using below xslt to transform the [XRef] element  </p>
  
  <pre><code>&lt;xsl:template match="XRef"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:attribute name="XRefType"&gt;(page xx)&lt;/xsl:attribute&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="@XRefType='(page xx)'"&gt;
                  &lt;xsl:attribute name="XRefPage" select="substring-before(substring-after(.,'(page '),')')"/&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:when test="@XRefType='xx'"&gt;
                  &lt;xsl:attribute name="XRefPage" select="."/&gt;
              &lt;/xsl:when&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>already gives me this output :</p>
  
  <pre><code>&lt;Paras&gt;
  &lt;Para tag="CorrectTag"&gt;
      &lt;local xml:lang="en"&gt;Look at this section&lt;XRef XRefType="(page xx)" XRefPage="36"/&gt;for more information&lt;/local&gt;
  &lt;/Para&gt;
  &lt;Para tag="InCorrectTag"&gt;
      &lt;local xml:lang="en"&gt;Look at some other section (page&lt;XRef XRefType="(page xx)" XRefPage="52"/&gt;) for more information&lt;/local&gt;
  &lt;/Para&gt;
  &lt;/Paras&gt;
  </code></pre>
  
  <p>Which is already solving most of my problem but I'm stuck on how I would get the rest of the [local] element cleaned without removing too much other content. </p>
  
  <p>What I need is something like : if the string "(page " is followed by an XRef element , then remove it. If the string ")" is preceded by an XRef element, remove it. Otherwise, don't touch them.</p>
  
  <p>Any advice on how to tackle this ?</p>
  
  <p>Thanks is advance !</p>