Re: [xsl] pulling child elements up to sibling level

Subject: Re: [xsl] pulling child elements up to sibling level
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 23 May 2003 17:51:29 +0100
  My target schema only allows lists and such as siblings of paragraphs, thus
  I need to transform the document into something like this:

This is what I use in the stylesheet for the mathml spec to pull inline
lists tables and stuff out for the utterly useless content model of an
html p.  Adjust the list of elements to taste.


<!-- xmlspec, like most document formats other than html, allows
    block level elements in paragraphs. For hTML need to
    separately wrap each conecutive run of inline elements in <p>
    and leave block level elements outside the p.

   xmlspec.xsl has some code using disable-output-escaping to
   attempt to do this, but it doesn't really work, even with processors
   that support d-o-e. The original mathml stylesheet as used for
   mathml 1.01 had code to deal with this, but this is a more
   efficient implementation using the grouping technique using keys.

<xsl:key name="pnodes" match="p/node()" 
       or self::glist
       or self::olist
       or self::ulist
       or self::slist
       or self::orglist
       or self::table
       or self::issue
       or self::note
       or self::processing-instruction()
       or self::graphic[not(@role='inline')]

<xsl:template match="p">
<xsl:variable name="p1">
        <xsl:if test="@id">
         <xsl:attribute name="id"><xsl:value-of
 <xsl:if test="@role">
   <xsl:attribute name="class">
      <xsl:value-of select="@role"/>
 <xsl:apply-templates select="key('pnodes',generate-id(.))"/>
<xsl:if test="key('pnodes',generate-id(.))/self::* or normalize-space($p1)">
  <xsl:copy-of select="$p1"/>
<xsl:for-each select="eg|glist|olist|ulist|slist|orglist|
<xsl:apply-templates select="."/>
<xsl:variable name="p" select="key('pnodes',generate-id(.))[position() &gt; 1]"/>
 <xsl:if test="$p[self::* or normalize-space(.)]">
<xsl:apply-templates select="$p"/>


This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

 XSL-List info and archive:

Current Thread