xsl-list
[Top] [All Lists]

RE: [xsl] nodes() before and after a string delimiter

2009-10-29 07:28:47
Michael,

Thank you very much.

This is a simple and elegant solution. I did not know that I could use 
substring-before and after in such a way. Guess I was stuck on the 'string' 
part of the function name.

Once again thanks.

Marijan (Mario) Madunic
Publishing Specialist
New Flyer Industries

-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com] 
Sent: Wednesday, October 28, 2009 4:57 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] nodes() before and after a string delimiter

First find the text node containing the dash:

<xsl:variable name="textNode" select="text()[contains(.,' - ')][1] "/>

Create a <term> element containing all nodes preceding this text node, plus
the part of the text node before the dash:

<term>
   <xsl:copy-of select="$textNode/preceding-sibling::node()"/>
   <xsl:value-of select="substring-before($textNode, ' - ')"/>
</term>

Create a <definition> element containing everything that follows the dash:

<definition>
   <xsl:value-of select="substring-after($textNode, ' - ')"/> 
   <xsl:copy-of select="$textNode/following-sibling::node()"/>
</definition>

Regards,

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

-----Original Message-----
From: Mario Madunic [mailto:Mario_Madunic(_at_)newflyer(_dot_)com] 
Sent: 28 October 2009 19:25
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] nodes() before and after a string delimiter

I have the following element (I'm using Saxon9 and XSLT2)

<p>Crazing - 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 - (space en dash space) and only the first  - (space 
en dash space).

<p>
   <term>Crazing</term>
   <definition>Hairline cracking of the resin, giving it an 
opaque, <q>frosty</q> appearance.</definition> </p>

I'm used to breaking strings on delimiters and not worrying 
about any inline elements, but his time the inline elements matter. 
Is this a for-each-group solution? Break it into two 
for-each-groups and in the first test for a 
following-sibling[. = '-'] and the second test for the 
following-sibling[. = '-']. 

No need to apply templates at this point a copy-of will suffice.

Any insight would be appreciated.

Thanks

Marijan (Mario) Madunic
Publishing Specialist
New Flyer Industries

--------------------------------------------------------------------
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.


--~------------------------------------------------------------------
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>
--~--


--------------------------------------------------------------------
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.


--~------------------------------------------------------------------
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>
--~--