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

Re: illegal elements must go...

Subject: Re: illegal elements must go...
From: Gary L Peskin <garyp@xxxxxxxxxxxx>
Date: Thu, 24 Aug 2000 15:52:36 -0700
peskin solution
Jukka --

This one took me a LONG time!!  I should have a longer template to show
for it.  I'm still not sure I have the best solution but it does offer
the advantage that it does work on your input.  Since I don't know how
complicated the configuration of your input could get, this may only be
a starting point.

Here is the stylesheet I came up with:

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

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

<xsl:strip-space elements="entry" />

<xsl:template match="entry">

  <!-- Select valid nodes and the first in a group of invalid nodes -->

  <xsl:variable name="mynodes"
  select="para | jibii | node()[preceding-sibling::node()[1] = (../para
| ../jibii)]"/>

  <xsl:for-each select="$mynodes">
    <xsl:variable name="nextpos" select="position() + 1"/>
    <xsl:apply-templates select=".">
      <xsl:with-param name="stopper"
select="$mynodes[position()=$nextpos]"/>
    </xsl:apply-templates>
  </xsl:for-each>

</xsl:template>

<xsl:template match="para | jibii">
  <!-- Handle the valid nodes -->
  <xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="* | text()">
  <!-- And this picks up anything else -->
  <xsl:param name="stopper"/>
    <para>
      <xsl:copy-of select=". |
                 
following-sibling::node()[.=$stopper/preceding-sibling::node()]"/>
    </para>
</xsl:template>

</xsl:stylesheet>

HTH,
Gary

Jukka.T.Lehtinen@xxxxxxxxx wrote:
> 
> Hi all!
> 
> I have struggled couple of days with this problem (well, still new in XSLT).
> 
> I'm having parent element which can have many childrens (in source). But the
> result side (in DTD) there are fewer possible elements. So, solution I'm
> gonna do is to put those 'illegal' (in result side) elements childrens of
> para element(s).
> 
> e.g:
> 
> source:
> ---------------------------------------------
> <entry>
>         <para>sometext</para>
>         <jibii>sometext</jibiii>
>         sometext without tags - illegal
>         <zzz>illegal element in result</zzz>
>         <xxx>another illegal elem</xxx>
>     <jibii>this elem is good</jibii>
>     <xxx>another illegal</xxx>
> </entry>
> ---------------------------------------------
> 
> result I want:
> ---------------------------------------------
> <entry>
>         <para>sometext</para>
>         <jibii>sometext</jibiii>
>         <para>            <!-- this is my problem -->
>         sometext without tags - illegal
>         <zzz>illegal element in result</zzz>
>         <xxx>another illegal elem</xxx>
>         </para>           <!-- this is my problem -->
>     <jibii>this elem is good</jibii>
>         <para>
>     <xxx>another illegal</xxx>
>         </para>
> </entry>
> ----------------------------------------------
> 
> But, I want them so that one added para element have all forthcoming illegal
> elemnts in as its children(like in example). Not so that every illegal
> element has parent para element of its own. So I have to test if the element
> is illegal AND if the next element is also illegal, and next... and when
> next elemnt is  ok. then put </para> element before ok element. And that
> PCDATA text - children of entry is also giving me some extra gray hairs.
> 
> Any good solutions ???
> 
> I ja tried quite many different solutions and there were all quite wrong, so
> I'm not gonna add them there as a bad example :-).
> 
> Thanks very much in advance.
> 
> And cheers... this list rocks.
> 
> Jukka.


 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.