|
Subject: Re: [xsl] nodes() before and after a string delimiter From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Wed, 28 Oct 2009 20:52:36 +0100 |
I have the following element (I'm using Saxon9 and XSLT2)
<p>Crazing b Hairline cracking of the resin, giving it an opaque, <q>frosty</q> appearance.</p>
I need to break it into two halves like the following based on the b (space en dash space) and only the first b (space en dash space).
<p> <term>Crazing</term> <definition>Hairline cracking of the resin, giving it an opaque, <q>frosty</q> appearance.</definition> </p>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template> <xsl:template match="p">
<xsl:copy>
<xsl:variable name="this" select="."/>
<xsl:variable name="t" select="text()[1]"/>
<xsl:analyze-string select="$t" regex="(.*) b (.*)">
<xsl:matching-substring>
<term><xsl:value-of select="regex-group(1)"/></term>
<definition>
<xsl:value-of select="regex-group(2)"/>
<xsl:apply-templates select="$t/following-sibling::node()"/>
</definition>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:apply-templates select="$this/node()"/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:copy>
</xsl:template>does that but I have not tested against anything but your input sample. --
Martin Honnen http://msmvps.com/blogs/martin_honnen/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] nodes() before and after a st, Mario Madunic | Thread | RE: [xsl] nodes() before and after , Mario Madunic |
| [xsl] nodes() before and after a st, Mario Madunic | Date | [xsl] Create word elements from a s, Larry Hayashi |
| Month |