Digesting a table with XSL 2.0

I

Ian Clifton

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top