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

RE: creating canonRef from flat

Subject: RE: creating canonRef from flat
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 19 Sep 2003 16:45:49 +0100
book luk
> Starting with
> <r>Mateus 3.1-12; Lucas 3.1-20; </r>
> I want
> <parallelPassage>
>         <canonRef book="MAT" chapter="3" verse="1" verseEnd="12"/>
>         <canonRef book="LUK" chapter="3" verse="1" 
> verseEnd="20"/> </parallelPassage>
> 
> I have just switched to 2.0 as it seemed the regular 
> expressions would 
> help me here.

Yes, this kind of "up-conversion" is an excellent use case for
<xsl:analyze-string>

> My thinking is to look in <r> and replace "Mateus" with 
> "<book>MAT</book>" 
> and "Lucas" with "<book>LUK</book>" ... and all the rest
> and in a second pass change
> 
> <r><book>MAT</book> 3.1-12; <book>LUK</book> 3.1-20; </r>
> <r>
>         <book>MAT</book> 
>         <chapter>3</chapter>
>         <verse>1</verse>
>         <verseEnd>12</verseEnd> 
>         <book>LUK</book>
>         <chapter>3</chapter>
>         <verse>1</verse>
>         <verseEnd>20</verseEnd 
> </r>
> and then put in final form in third pass
> <parallelPassage>
>         <canonRef book="MAT" chapter="3" verse="1" verseEnd="12"/>
>         <canonRef book="LUK" chapter="3" verse="1" 
> verseEnd="20"/> </parallelPassage>
> 
> Am I headed in the right direction? Or are there some really neat 
> shortcuts?

I would have thought it could be done more easily than that. Something
like (untested):

<xsl:analyze-string select="r" regex="[^;]+">
  <xsl:matching-substring>
    <canonRef>
    <xsl:analyze-string select="." 
          regex="([^\s]+)\s([0-9]+)\.([0-9]+)\-([0-9]+)">
      <xsl:matching-substring>
        <xsl:attribute name="book" select="my:abbrev(regex-group(1))"/>
        <xsl:attribute name="chapter" select="regex-group(2)"/>
        <xsl:attribute name="verse" select="regex-group(3)"/>
        <xsl:attribute name="verseEnd" select="regex-group(4)"/>
      </
    </
    </canonRef>
  </
</

[Correction, xsl:attribute doesn't take a select attribute - but watch
this space]

<xsl:function name="my:abbrev">
  <xsl:param name="long-name"/>
  <xsl:variable name="table">
    <book long="Mateus" short="MAT"/>
    <book long="Lucas" short="LUK"/>
    ...
  </xsl:variable>
  <xsl:sequence select="$table/book[@long=$long-name]/@short"/>
</xsl:function>

> If I use replace will I need to have it nested 66 times to 
> account for all 
> books?

No, use a lookup table as above.
> 
> 
> Jim Albright
> 704 843-0582
> Wycliffe Bible Translators
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.