xsl-list
[Top] [All Lists]

RE: preceding/following character?

2005-06-17 03:53:02
One solution to this kind of problem is to replace the markup by text, and
then treat it as an analyze-string problem:

<xsl:template match="bar">
  <xsl:text>%bar%</xsl:text>
</xsl:template>

<xsl:template match="foo">
  <foo_out>
    <xsl:variable name="temp" as="xs:string">
      <xsl:value-of>
         <xsl:apply-templates/>
      </xsl:value-of>
    </xsl:variable>
    <xsl:analyze-string select="$temp" regex="%bar%\.">
      <xsl:matching-substring>
        <xsl:text>. </xsl:text>
        <bar_out/>
      </
    </
  </
</

An alternative approach is to treat it as a positional grouping problem:

<xsl:for-each-group select="node()" 
  group-starting-with="bar[starts-with(following-sibling::node()[1], '.')]">
  <xsl:text>. </xsl:text>
  <bar_out/>
  <xsl:value-of select="substring-after(current-group()[2], '.')"/>
  <xsl:copy-of select="current-group()[position() gt 2]"/>
</xsl:for-each-group>

Michael Kay
http://www.saxonica.com/
    

-----Original Message-----
From: Bruce D'Arcus [mailto:bdarcus(_at_)gmail(_dot_)com] 
Sent: 17 June 2005 02:11
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] preceding/following character?

Say I have source with mixed content like:

<foo>Some text and more text <bar/>. Some more text.</foo>

I need a "bar" matched template that will under certain 
conditions move 
that period that immediately follows the element to be ahead it.

E.g., in some conditions, output would be:

<foo_out>Some text and more text.<bar_out/> Some more text.</foo_out>

This seems like a simple problem, but I can't really fathom how to 
solve it.  I'm using XSLT 2.0.

Bruce


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--