Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Digesting a table with XSL 2.0 (http://www.velocityreviews.com/forums/t745096-digesting-a-table-with-xsl-2-0-a.html)

Ian Clifton 03-14-2011 03:32 PM

Digesting a table with XSL 2.0
 
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

Martin Honnen 03-14-2011 03:45 PM

Re: Digesting a table with XSL 2.0
 
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/fun...for-regex.html for an
approach how to do that.


--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/

Ian Clifton 03-14-2011 04:38 PM

Re: Digesting a table with XSL 2.0
 
Martin Honnen <mahotrash@yahoo.de> 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/fun...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 ian.clifton@chem.ox.ac.uk
Mansfield Road Oxford OX1 3TA UK


All times are GMT. The time now is 03:47 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.