This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: illegal elements must go...




Hi Jukka,
The stylesheet below doesn't do _everything_ you need but it might put you on
the right track. Specifically, it does not consolidate adjacent para tags with
the newly constructed para tags.
I hope this helps somewhat, I tested it on msxml July version with your sample
input and it seemed to work fine.
Michal

PS If anyone can post a better way to do this that'll be great.

travis inspired xml input:
====================
<entry>
     <para>Everyday I wake up alone</para>
     <jibii>I'm not like all the other boys</jibii>
     And ever since I was young
     <zzz>I had no choice</zzz>
     <xxx>But it's OK to lead me on</xxx>
    <jibii>I admit it's not much fun</jibii>
    <xxx>To be led on by such a one</xxx>
     As you are
</entry>

xsl stylesheet:
============


     <xsl:template match="/">
          <HTML>
          <HEAD></HEAD>
               <BODY>

                    <xsl:for-each select="entry/* | entry/text()" >

                    <xsl:apply-templates select="." />

                    </xsl:for-each>
               </BODY>
          </HTML>
     </xsl:template>

<xsl:template match="(zzz|xxx|text())
                         [not(preceding-sibling::node()[1][name()='zzz']) and
                          not(preceding-sibling::node()[1][name()='xxx']) and
                          not(preceding-sibling::node()[1][name()='']) ]">
     <xsl:element name="para">
     <xsl:apply-templates select="." mode="output"/>
     </xsl:element>


</xsl:template>

<xsl:template match="zzz|xxx|text()" mode="output">

     <xsl:text>&#xa;</xsl:text>
     <xsl:choose>
     <xsl:when test="name()=''">
          <xsl:value-of select="."/>
     </xsl:when>
     <xsl:otherwise>
          <xsl:element name="{name()}">
          <xsl:value-of select="."/>
          </xsl:element>
     </xsl:otherwise>
     </xsl:choose>
     <xsl:apply-templates select="following-sibling::node()[1]" mode="output"/>

</xsl:template>

<xsl:template match="*|text()"/>
<xsl:template match="*" mode="output"/>

<xsl:template match="jibii|para">
     <xsl:element name="{name()}">
     <xsl:value-of select="."/>
     </xsl:element>

</xsl:template>





Jukka.T.Lehtinen@nokia.com on 08/24/2000 03:53:16 AM

Please respond to xsl-list@mulberrytech.com

To:   xsl-list@mulberrytech.com
cc:    (bcc: Michal Mart)

Subject:  illegal elements must go...




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







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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]