[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] nodes() before and after a string delimiter
Subject: RE: [xsl] nodes() before and after a string delimiter From: "Mario Madunic" <Mario_Madunic@xxxxxxxxxxxx> Date: Thu, 29 Oct 2009 06:29:59 -0500 |
Martin, Thanks for the quick reply and solution. This is definitely one for the toolbox. Marijan (Mario) Madunic Publishing Specialist New Flyer Industries -----Original Message----- From: Martin Honnen [mailto:Martin.Honnen@xxxxxx] Sent: Wednesday, October 28, 2009 2:53 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] nodes() before and after a string delimiter Mario Madunic wrote: > 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> This stylesheet <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output indent="yes"/> <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> </xsl:stylesheet> does that but I have not tested against anything but your input sample. -- Martin Honnen http://msmvps.com/blogs/martin_honnen/ -------------------------------------------------------------------- Please consider the environment before printing this e-mail. CONFIDENTIALITY STATEMENT: This communication (and any and all information or material transmitted with this communication) is confidential, may be privileged and is intended only for the use of the intended recipient. If you are not the intended recipient, any review, retransmission, circulation, distribution, reproduction, conversion to hard copy, copying or other use of this communication, information or material is strictly prohibited and may be illegal. If you received this communication in error or if it is forwarded to you without the express authorization of New Flyer, please notify us immediately by telephone or by return email and permanently delete the communication, information and material from any computer, disk drive, diskette or other storage device or media. Thank you.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] nodes() before and after , Martin Honnen | Thread | RE: [xsl] nodes() before and after , Michael Kay |
RE: [xsl] nodes() before and after , Mario Madunic | Date | Re: [xsl] reading a text file and p, a kusa |
Month |