[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Using analyze-string to catch roman numerals?

Subject: Re: Using analyze-string to catch roman numerals?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 09 Oct 2008 15:50:18 -0400
Re:  Using analyze-string to catch roman numerals?
At 2008-10-09 15:18 -0400, Tony Zanella wrote:
Given the following input:
...
and the following template:
...
I'm trying to use analyze-string to do the following:
Test for a roman numeral. If there isn't one, lower-case(.). If there
is one, break (.) into its roman numeral and non-roman numeral parts,
lower-case()ing the latter.

You are doing too much in your regular expression and need to treat it more piecemeal.


Hopefully you'll be satisfied identifying a Roman numeral as:

(\W|^)([IVXL]+)(\W|$)

But that won't help you with:

Chapter II. What I Did On My Summer Vacation

... because you'll get:

chapter II. what I did on my summer vacation

... and the non-Roman numeral will still be upper case.

When what I want is this:

        chapter II. the wrecked foundations of domesticity
        problema. heloise XXIX.
        selected letters
        the second part of henry IV.
        VIII
        appendix VII
        appendix VII
        appendix
        calvin XVII
        illustration

 Between my relative inexperience with both regexes and XSLT, thanks
for any help!

I hope the below helps.


. . . . . . . . . . . . Ken

T:\ftemp>xslt2 tony.xml tony.xsl con

    chapter II. the wrecked foundations of domesticity
    problema. heloise XXIX.
    selected letters
    the second part of henry IV.
    VIII
    appendix VII
    appendix VII
    appendix
    calvin XVII
    illustration

T:\ftemp>type tony.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                exclude-result-prefixes="xsd"
                version="2.0">

<xsl:output method="text"/>

<xsl:template match="head">
  <xsl:analyze-string select="." regex="(\W|^)([IVXL]+)(\W|$)">
    <xsl:matching-substring>
      <xsl:value-of select="."/>
    </xsl:matching-substring>
    <xsl:non-matching-substring>
      <xsl:value-of select="lower-case(.)"/>
    </xsl:non-matching-substring>
  </xsl:analyze-string>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>type tony.xml
<root>
    <head>CHAPTER II. THE WRECKED FOUNDATIONS OF DOMESTICITY</head>
    <head>PROBLEMA. HELOISE XXIX.</head>
    <head>Selected Letters</head>
    <head>The Second Part of Henry IV.</head>
    <head>VIII</head>
    <head>APPENDIX VII</head>
    <head>Appendix VII</head>
    <head>APPENDIX</head>
    <head>CALVIN XVII</head>
    <head>ILLUSTRATION</head>
</root>


T:\ftemp>


--
Upcoming XSLT/XSL-FO hands-on courses:      Wellington, NZ 2009-01
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video sample lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg
Video course overview:  http://www.youtube.com/watch?v=VTiodiij6gE
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.