Re: [xsl] unparsed-text and analyze-string

Subject: Re: [xsl] unparsed-text and analyze-string
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 21 Jan 2008 17:27:16 -0500
At 2008-01-21 17:03 -0500, Terry Ofner wrote:
My question: how do I design a single sheet that will iterate through
various regex expressions.

You don't need to.

I would like to avoid a situation where I
am piping the output of one stylesheet through another if at all
possible. Also, is it possible to use unparsed-text with text that
already contains some elements?

No, because the element structure is not preserved.

My goal is to use XSLT in the place of a manual markup process if at
all possible.

A good goal to have!

Any hints would be most appreciated.

You didn't notice that there is an "alternatives" operator "|" available for regular expressions. "a|b" matches either the pattern "a" or the pattern "b".

I hope the working example below helps.

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

t:\ftemp>type terry.txt 1 XSLT means-- (G6U1S01) A extensible stylesheet language transformations. B extremely sly lexical transformations. C XML stylesheet language transformations. D all the above

        2       Stem
                display sentence (optional)
                stem part 2 (optional)  (G6U1S01)
        A       answer choice
        B       answer choice
        C       answer choice
        D       answer choice

t:\ftemp>type terry.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="";

<xsl:param name="input-uri"/>
<xsl:output indent="yes"/>

<xsl:template name="main">
  <xsl:variable name="in"
              select="unparsed-text($input-uri, 'UTF-8')"/>

<xsl:analyze-string select="$in"
      <xsl:when test="matches(.,'\(G')">
        <xsl:element name="notes">
          <xsl:value-of select="regex-group(1)"/>
        <xsl:variable name="choiceLetter" select="regex-group(2)"/>
        <xsl:variable name="choiceLower" select="lower-case($choiceLetter)"/>
        <xsl:element name="choice-{$choiceLower}">
          <xsl:value-of select="regex-group(3)"/>
     <xsl:value-of select="."/>


t:\ftemp>saxon9 -it:main terry.xsl input-uri=terry.txt

t:\ftemp>java -Xms200m -Xmx700m -jar p:\xml\xslt\saxon9\saxon9.jar -it:main terry.xsl input-uri=terry.txt
<?xml version="1.0" encoding="UTF-8"?> 1 XSLT means-- <notes>G6U1S01</notes>
<choice-a>extensible stylesheet language transformations.</choice-a>
<choice-b>extremely sly lexical transformations.</choice-b>
<choice-c>XML stylesheet language transformations.</choice-c>
<choice-d>all the above</choice-d>

        2       Stem
                display sentence (optional)
                stem part 2 (optional)  <notes>G6U1S01</notes>
<choice-a>answer choice</choice-a>
<choice-b>answer choice</choice-b>
<choice-c>answer choice</choice-c>
<choice-d>answer choice</choice-d>


World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Nov'07
Legal business disclaimers:

Current Thread