fn:matches regex

  • Tobias Klevenz

    Tobias Klevenz - 2009-07-29

    Hi, there.
    Just to follow up on a comment I posted on Twitter the other day.

    Here's what the Problem was:

    I had an XML like:
    <b Code="it1">value</b>
    <b Code="it2">value</b>
    <b Code="it3">value</b>

    <b Code="it1_1">value1</b>
    <b Code="it2_1">value1</b>
    <b Code="it3_1">value1</b>

    I had to put them in a table so that it1_1 belongs to it1 so I did:

    <xsl:for-each select="b[matches(@Code,'it[0_9][^_]')]">

    trying to only select the it but not it_1 (using Oxygen if I search for it[0_9][^_] with regex enabled this works fine)

    Running the Transformation with saxon however, this didn't select anything.

    I quickly worked around it with a combination of contains and substring-after.

    Question though, shouldn't that regex work in the transformation?


    • Michael Kay

      Michael Kay - 2009-07-29

      Did you mean it[0-9][^_] perhaps?

      My understanding is that this matches "it" followed by a digit followed by a character that is not an underscore. It won't match "it5" because the digit is not followed by a character that matches [^_]. Perhaps you should use "^it[0-9]$"

      • Tobias Klevenz

        Tobias Klevenz - 2009-07-29

        "followed by a character that is not an underscore"
        True, I didn't think of it that way, I guess the way Oxygen handles that "no charachter" or maybe \b which marks the end of the Word as I understand is included in that too.

        I guess it depends on the implementation of regex then.

        Regex is still kind of a mystery to me, that is really fun playing with though.


        • Michael Kay

          Michael Kay - 2009-07-29

          Oxygen is probably searching the raw XML text, in which case the [^_] matches the closing quote of the attribute value.

          There's no \b in XPath regular expressions because of internationalization issues.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks