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

Converting milestone tags

Subject: Converting milestone tags
From: Josef Schneeberger <josef@xxxxxxxxxxxxxxxxxx>
Date: Thu, 14 Oct 2010 14:05:47 +0700
 Converting milestone tags
Hi everybody,

I am new to this list and apologize, if my question is an FAQ. I scanned
the archives, but did not find a solution. The question arises in a TEI
project where we have to switch from a chapter hierarchy to a page
oriented form. The XSLT is done in multiple steps (a cocoon pipeline)
and I use Saxon9.

Here is a simplified example of an infile:

<root>
 <p>text <span order="start"/>text<span order="end"/> text</p>
 <p>text <span order="start"/>text<span order="end"/> text
    text <span order="start"/>text<span order="end"/> text</p>
 <p>text text text <span order="start"/>text<span order="end"/></p>
 <p><span order="start"/>text<span order="end"/> text text text</p>
</root>

which should result in the following output:

<root>
 <p>text <span>text</span> text</p>
 <p>text <span>text</span> text
    text <span>text</span> text</p>
 <p>text text text <span>text</span></p>
 <p><span>text</span> text text text</p>
</root>

There my be an arbitrary number of <span order="begin"/> (and
corresponding end milestone tags) in a p element. Furthermore, any
"text" node may again contain markup which should be preserved in the
output. I tried various approaches but I failed. Here is one of my
attempts using sibling recursion ...

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
  <xsl:apply-templates/>
 </xsl:template>
	
 <xsl:template match="root">
  <root><xsl:apply-templates/></root>
 </xsl:template>
	
 <xsl:template match="p">
  <p>
   <xsl:apply-templates select="child::node()" mode="procp"/>
  </p>
 </xsl:template>
	
 <xsl:template match="span[@order='start']" mode="procp">
  <span>
   <xsl:apply-templates
     select="following-sibling::node()[1][not(self::span)]"
     mode="procp"/>
  </span>
  <xsl:apply-templates select="following-sibling::node()[1]"/>
 </xsl:template>
	
 <xsl:template match="node()" mode="procp">
  <xsl:copy-of select="."/>
   <xsl:apply-templates
      select="following-sibling::node()[1][not(self::span)]"
      mode="procp"/>
 </xsl:template>
</xsl:stylesheet>

Any help would be greatly appreciated. Josef

-- 
Josef Schneeberger
josef@xxxxxxxxxxxxxxxxxx
Nuernberg, Germany

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.