[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT 2.0 grouping and text nodes and mixed text

Subject: XSLT 2.0 grouping and text nodes and mixed text
From: Kenneth Reid Beesley <krbeesley@xxxxxxxxx>
Date: Tue, 8 Dec 2009 16:52:23 -0700
 XSLT 2.0 grouping and text nodes and mixed text
Relative newbie question: XSLT 2.0, grouping with text nodes and mixed text

I'm trying to convert a non-XML dictionary into XML. I've got it mostly done, but I want to input
elements that currently look like


<examples>
   <hop>source sentence 1</hop>
   translation of source sentence 1
   <hop>source sentence 2</hop>
   translation of source sentence 2
   <hop>source sentence 3</hop>
   a translation can be <emph>mixed</emph> text
</examples>

and transform them into this

<examples>
    <example-pair>
       <hop>source sentence 1</hop>
       <eng>translation of source sentence 1</eng>
   </example-pair>
   <example-pair>
      <hop>source sentence 2</hop>
      <eng>translation of source sentence 2</eng>
   </example-pair>
   <example-pair>
      <hop>source sentence 3</hop>
      <eng>a translation can be <emph>mixed</emph> text</eng>
   </example-pair>
</examples>

i.e. each original <hop> element in <examples> is followed by plain text or mixed text,
not containing <hop> or <examples> elements. I want to group the nodes after each
<hop> element and wrap them in <eng>...</eng> tags. I tried the following, and a few
other variations, but the desired <eng> element comes out an empty <eng/>



<?xml version="1.0" encoding="UTF-8"?>


<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform ">

<xsl:output method="xml" indent="yes"/>

	<xsl:template match="examples">
		<examples>
		<xsl:for-each-group select="*" group-starting-with="hop">
			<example-pair>
				<!-- copy the hop element-->
				<xsl:copy-of select="."/>
				<!-- and then surround the mixed text following the hop element
					 with eng tags -->
				<eng>
					<xsl:apply-templates select="current-group() except ."/>
				</eng>
			</example-pair>
		</xsl:for-each-group>
		</examples>
	</xsl:template>

	<!-- default copying of the document -->
	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>

</xsl:stylesheet>

Would some kind guru please tell me how I can do this?

Thanks,

Ken

******************************
Kenneth R. Beesley, D.Phil.
P.O. Box 540475
North Salt Lake, UT
84054  USA

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.