4

I am trying to apply XSLT on SVN log, I need to extract bug numbers from the commit messages. I am applying this regex on msg but get nothing back. What am I missing in XSLT? Thank you in advance Below is XML that I get from SVN:

<?xml version="1.0" encoding="UTF-8"?>
<log>
	<logentry revision="265">
	<author>dre</author>
    <date>2015-04-13T02:35:25.246150Z</date>
    <msg>modified code</msg>
</logentry>
<logentry revision="73283">
	<author>john</author>
	<date>2015-04-13T14:10:20.987159Z</date>
	<msg>fixed bug DESK-1868</msg>
</logentry>
<logentry revision="73290">
	<author>ron</author>
	<date>2015-04-13T14:24:57.475711Z</date>
	<msg>WEBAPP-1868 Fix for pallete list and settings dialog Selected Tab Index</msg>
</logentry>
</log>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>SVN Issues</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th style="text-align:left">ver</th>
        <th style="text-align:left">author</th>
        <th style="text-align:left">date</th>
        <th style="text-align:left">ticket</th>
      </tr>
      <xsl:for-each select="log/logentry">
      <tr>
        <td><xsl:value-of select="@revision"/></td>
        <td><xsl:value-of select="author"/></td>
        <td><xsl:value-of select="date"/></td>
        <td>
            
                <xsl:variable name="messageValue" select="msg"/>
                <xsl:analyze-string select="$messageValue" 
                  regex="(DESK|TRS|PEK|WEBAPP)-\d{4}$">
                      <xsl:matching-substring>
                         <bug><xsl:value-of select="regex-group(1)"/></bug>
                      </xsl:matching-substring>
                </xsl:analyze-string>
        </td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

4
  • I changed the version, but still not getting anything in back for that field Commented Sep 18, 2015 at 22:29
  • 2
    You need to double up your {} in your regex...regex="(DESK|TRS|PEK|WEBAPP)-\d{{4}}$". xsltransform.net/94rmq5D (Not sure why you're using $ to match the end of the string. It will only return something on the second logentry like that.) Also, be sure that you're using an XSLT 2.0 processor. Commented Sep 18, 2015 at 22:44
  • double {} helped, and I am usig XSLT 2.0 now. I see DESK as a result. Commented Sep 19, 2015 at 16:42
  • instead of using regex-group(), use . instead. See the link in my previous comment. It returns what you want. Commented Sep 19, 2015 at 20:08

1 Answer 1

5
  1. http://www.w3.org/TR/xslt20/#analyze-string

    Note: Because the regex attribute is an attribute value template, curly brackets within the regular expression must be doubled. For example, to match a sequence of one to five characters, write regex=".{{1,5}}". For regular expressions containing many curly brackets it may be more convenient to use a notation such as regex="{'[0-9]{1,5}[a-z]{3}[0-9]{1,2}'}", or to use a variable.

  2. You do not want to anchor your expression to the end of the line using $ at the end of your expression. Otherwise the regex will only match when the message ends with an issue ID.

Use this regex expression to capture the entire bug number:

regex="((DESK|TRS|PEK|WEBAPP)-\d{{4}})"
Sign up to request clarification or add additional context in comments.

3 Comments

Almost work... When I test the regex against a string I get WEBAPP-1868, but when I use it in XSL - I only get WEBAPP
Do you want the number, or the entire bug ID? Simply adjust the regex to put the parenthesis for the capture group to include what you want. It is helpful to specify the desired outcome in your question.
I wanted WEBAPP-1868. After adding parenthesis I get exactly what I wanted. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.