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

Creating a container element for siblings which have

Subject: Creating a container element for siblings which have different start and end elements
From: "Michael Friedman sumarimike@xxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 29 Jan 2015 16:25:06 -0000
 Creating a container element for siblings which have
Greetings,
 
I have some XML which has certain elements Id like to move into a containing
element. Im having trouble.
 
The current XML is arranged this way:
<para>Planes have wings so they can <tech:revst
type="Airline"/>fly<tech:revend/> in the sky and get us to places wed like to
visit faster <tech:revst type="Airline"/>than if wed walked there.<caution>
<para>Please stay in the airplane at all
times</para></caution><tech:revend/></para>
 
In this older method of indicating a revision markup area, <tech:revst/> is
used to indicate a start of a change and <tech:revend> is used to indicate the
end. There can be multiple instances of this revision markup anywhere,
surrounding text within elements, or surrounding multiple elements and text.
These containers produce change bars in PDF and background-color areas in
HTML.
 
I am producing PDF and HTML output. In order to create a <span> or <div> in
HTML output, Id like to pre-process the XML to produce the following desired
XML output structure.
 
Desired output:
<para>Planes have wings so they can <tech:revst
type="Airline">fly</tech:revst><tech:revend/> in the sky and get us to places
wed like to visit faster <tech:revst type="Airline">than if wed walked
there.<caution>
<para>Please stay in the airplane at all
times</para></caution></tech:revst><tech:revend/></para>
 
Essentially, Id like to encapsulate the siblings between the <tech:revst/>
and <tech:revend/> into the <tech:revst>. The <tech:revend/> is left in for FO
processing.
 
Using XSLT 2.0, Ive been able to get the first <tech:revst> in a given
sibling structure partially handled. However, the remaining ones (in this
case) are omitted. Im using saxon 6 via our publishing app to do the heavy
lifting.
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                        xmlns:tech="http://www.techpubsglobal.com/"
                        version="2.0">
                       
    <xsl:output method="xml" indent="no" doctype-public="-//Tech//DTD
FlightBook XML V4.0//EN" doctype-system="flightbook.dtd"/>

    <xsl:template match="/|*|comment()|processing-instruction()">
       <xsl:call-template name="do_copy"/>
    </xsl:template>

    <xsl:template match="tech:revst">
            <xsl:element name="tech:revst">
                  <xsl:for-each select="@*">
                        <xsl:attribute name="{name(.)}">
                  <xsl:value-of select="."/>
                </xsl:attribute>
            </xsl:for-each>
                  <xsl:for-each
select="following-sibling::*[not(self::tech:revend)][not(preceding-sibling::t
ech:revend)]|following-sibling::text()[preceding-sibling::tech:revst][followi
ng-sibling::tech:revend]">
                        <xsl:copy>
                        <xsl:for-each select="@*">
                                    <xsl:copy/>
                              </xsl:for-each>
                              <xsl:apply-templates/>
                    </xsl:copy>
                  </xsl:for-each>
            </xsl:element>
      </xsl:template>

      <xsl:template
match="*[preceding-sibling::tech:revst][following-sibling::tech:revend]"/>
      <xsl:template
match="text()[preceding-sibling::tech:revst][following-sibling::tech:revend]"
/>
    
      <xsl:template name="do_copy">
          <xsl:copy>
            <xsl:for-each select="@*">
                        <xsl:copy/>
                  </xsl:for-each>
                  <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
                       
</xsl:stylesheet>
 
The following is produced from this stylesheet:
<para>Planes have wings so they can <tech:revst type="Airline">fly in the sky
and get us to places wed like to visit faster than if wed walked
there.</tech:revst><tech:revend/></para>
 
I found some useful suggestions on grouping on the dpawson.co.uk site, but
each one I tried didnt quite get me what I was looking for. In particular,
there was a Working with pairs of siblings that used sequences, but I still
couldnt get that to work when there were multiple <tech:revst/><tech:revend/>
pairs in a set of siblings.
 
Suggestions?
 
Thanks,
Michael Friedman

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.