Digesting a table with XSL 2.0

Discussion in 'XML' started by Ian Clifton, Mar 14, 2011.

  1. Ian Clifton

    Ian Clifton Guest

    Hello,

    I'm trying to get my XSL 2.0 stylesheet to digest tables which look like
    this: (they are in a file imported by unparsed-text() )

    Rmerge 0.126 0.027 1.857
    Rmeas (within I+/I-) 0.135 0.029 2.000
    Rmeas (all I+ & I-) 0.142 0.045 1.994
    Rpim (within I+/I-) 0.049 0.011 0.738
    Rpim (all I+ & I-) 0.038 0.012 0.531

    I'd like the output to look like this:

    <Rmerge shell="Overall">0.126</Rmerge>
    <Rmerge shell="Inner">0.027</Rmerge>
    <Rmerge shell="Outer">1.857</Rmerge>

    In my stylesheet I have a sequence of "prefixes"

    <xsl:variable name="table_prefixes" as="xs:string+" select="'Rmerge',
    'Rmeas (within I+/I-)', 'Rmeas (all I+ &amp; I-)', 'Rpim (within
    I+/I-)', 'Rpim (all I+ &amp; I-)'"/>

    and I look for each prefix like this:

    <xsl:for-each select="$table_prefixes">
    <xsl:message select="concat('Pos:',position(),'Looking for:',.)"/>
    <xsl:variable name="pos" as="xs:integer" select="position()"/>
    <xsl:analyze-string select="$table_block"
    regex="\s*{.}\s*([\d\.]+)\s*([\d\.]+)\s*([\d\.]+)\s*\n">
    <xsl:matching-substring>
    <xsl:element name="{$node_names[$pos]}">
    <xsl:attribute name="shell">Overall</xsl:attribute>
    <xsl:value-of select="regex-group(1)"></xsl:value-of>
    </xsl:element>
    <xsl:element name="{$node_names[$pos]}">
    <xsl:attribute name="shell">Inner</xsl:attribute>
    <xsl:value-of select="regex-group(2)"></xsl:value-of>
    </xsl:element>
    <xsl:element name="{$node_names[$pos]}">
    <xsl:attribute name="shell">Outer</xsl:attribute>
    <xsl:value-of select="regex-group(3)"></xsl:value-of>
    </xsl:element>
    </xsl:matching-substring>
    </xsl:analyze-string>
    </xsl:for-each>

    of course, the problem is some of my prefixes contain characters which
    are special in regular expressions. I could just suitably escape them
    all, but I've got a feeling there ought to be a different, easier
    approach. Any ideas?

    Thanks,
    --
    Ian Clifton
    Ian Clifton, Mar 14, 2011
    #1
    1. Advertising

  2. Martin Honnen, Mar 14, 2011
    #2
    1. Advertising

  3. Ian Clifton

    Ian Clifton Guest

    Martin Honnen <> writes:

    > Ian Clifton wrote:
    >
    >> of course, the problem is some of my prefixes contain characters which
    >> are special in regular expressions. I could just suitably escape them
    >> all, but I've got a feeling there ought to be a different, easier
    >> approach. Any ideas?

    >
    > I think you need to escape them, see
    > http://www.xsltfunctions.com/xsl/functx_escape-for-regex.html for an
    > approach how to do that.


    Excellent, thank you, I've got it working now. (I've just found out
    though that U+00B1 can't be an XML NameChar.)
    --
    Ian Clifton Phone: +44 1865 275677
    Chemistry Research Laboratory Fax: +44 1865 285002
    Oxford University
    Mansfield Road Oxford OX1 3TA UK
    Ian Clifton, Mar 14, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Flood
    Replies:
    0
    Views:
    1,017
    Kevin Flood
    Sep 8, 2004
  2. Kevin Flood
    Replies:
    1
    Views:
    2,728
    Kevin Flood
    Sep 13, 2004
  3. Klaus Friese
    Replies:
    0
    Views:
    466
    Klaus Friese
    Nov 22, 2004
  4. Replies:
    1
    Views:
    3,595
    A. Bolmarcich
    May 27, 2005
  5. Tina

    Digesting a Doc file

    Tina, Jul 26, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    431
Loading...

Share This Page