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

Re: Checking node position

Subject: Re: Checking node position
From: Gary L Peskin <garyp@xxxxxxxxxxxx>
Date: Fri, 01 Sep 2000 12:02:14 -0700
david w. black editor
"David W. Black" wrote:
> I essentially have an undifferentiated list of elements (old html) that I need to > transform to xml, and the only hooks I have are certain textual consistencies:
> 
> <p>textxtxtxt</p>
> <p>head1</p>
> <p>text_associated_semantically_with_head1</p>
> <p>text_associated_semantically_with_head1</p>
> <p>head2</p>
> 
> etc.
> 
> Thus I want to itentify the position of the <p> with text="head1" (ie. 2), the
> position of <p> with text="head2" (ie.5) so that I can then wrap all <p>s between 2
> and 5 with an element in the result tree.
>
> I can, I suppose, pre-process using generate-id() to ascribe and id attribute to each 
> <p> and then do my transformations.... but I'd really like to ties this up in one
> stylesheet, not two?
> 
> Any ideas, anyone??

David --

I'm not 100% sure what you want to do but you did say "any ideas".  I
think this will get you started:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="parent" match="p"
  use="generate-id(preceding-sibling::p[. = 'head1' or . = 'head2'])" />

<xsl:template match="p[. = 'head1' or . = 'head2']">
  <xsl:element name="{.}">
    <xsl:apply-templates
      select="key('parent', generate-id())[. != 'head1' and . !=
'head2']"
          mode="inner"/>
    </xsl:element>
</xsl:template>

<xsl:template match="p"/>

<xsl:template match="p" mode="inner">
  <sub>
    <xsl:copy-of select="."/>
  </sub>
</xsl:template>

</xsl:stylesheet>

HTH,
Gary


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.