This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: illegal elements must go...
- To: xsl-list at mulberrytech dot com
- Subject: Re: illegal elements must go...
- From: Gary L Peskin <garyp at firstech dot com>
- Date: Thu, 24 Aug 2000 15:52:36 -0700
- Organization: The Firstech Corporation
- References: <11CD408013B6D2119BB50008C7EA510C03ED068F@eseis05nok>
- Reply-To: xsl-list at mulberrytech dot com
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@nokia.com 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