RE: [xsl] problem creating containment during XHTML->XML

Subject: RE: [xsl] problem creating containment during XHTML->XML
From: "Josh Canfield" <Josh.Canfield@xxxxxxxxxxxx>
Date: Mon, 23 Feb 2004 15:00:57 -0800
I'm not sure why you are seeing an infinite loop with your code. When I removed the namespace "x" and ran it with the xml that you provided it dumped the output I would expect, although not the output you want. 

The basic problem is that 
      <xsl:apply-templates select="following-sibling::*" /> 

is going to include the heading nodes. When a heading node is encountered it will recurse back into the heading template and evaluate all of it's children.


Here is a template creates the output as you have specified. I wrapped your xml in an element named root.

  <xsl:template match="/root">
    <xsl:apply-templates select="heading"/>
  </xsl:template>

  <xsl:template match="heading">
    <section>
      <xsl:copy>
        <xsl:copy-of select="@*"/>
        <xsl:value-of select="."/>
      </xsl:copy>
	<!-- copy all of the following siblings, that are not "heading" nodes, 
	which have the current heading node as it's first preceding heading node sibling -->
      <xsl:copy-of select="following-sibling::*[
                              name() != 'heading' and 
                              preceding-sibling::heading[1] = current() 
                            ] "/>
    </section>
    
  </xsl:template>

Hope this helps,
Josh

-----Original Message-----
From: Don Stinchfield [mailto:des@xxxxxxxx]
Sent: Monday, February 23, 2004 2:07 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] problem creating containment during XHTML->XML 


Hello,

I'm having a devil of a time trying to create the right node set for my
processing.  Any help would be appreciated. :-)

I'm in the process of breaking up an XHTML file into multiple XML files.
Here's the portion of the input file that's of interest (I've already
Modified the file by replacing HTML headings with a heading tag)...

  [lots of html cruft]
  <heading level="h1"><a name="content" id="content"></a>Overview</heading>
    <p>On February 20, 1865</p>
    <p>Education and related research&#8212; 
    <a href="degre.archi.deans.shtml">Architecture and Planning</a>; 
    <a href="degre.engin.deans.shtml">Engineering</a>;</p>
  <heading level="h3"><a name="mission" id="mission"></a>Mission</heading>
    <p>The mission of </p>
    <p>The Institute is committed to </p>
  <heading level="h3"> <a name="sf" id="sf"></a>Faculty</heading>
    <p> total enrollment is approximately 10,300 students</p>
    <p>The faculty numbers approximately 956</p>
  [lots of html cruft]

I'm cleaning up a bit and would like to add structure as follows...

  <section>
    <heading level="h1">Overview</heading>
      <p>On February 20, 1865</p>
      <p>Education and related research&#8212;   
      <a href="degre.archi.deans.shtml">Architecture and Planning</a>; 
      <a href="degre.engin.deans.shtml">Engineering</a>;</p>
  </section>
  <section>
    <heading level="h3"></a>Mission</heading>
      <p>The mission of </p>
      <p>The Institute is committed to </p>
  </section>
  <section>
    <heading level="h3">Faculty</heading>
      <p> total enrollment is approximately 10,300 students</p>
      <p>The faculty numbers approximately 956</p>
  </section>

In a final phase I'll break the file up.  One xml file per section.

Here's the XSLT file.  I've been working with.

- <xsl:template match="/">
    <xsl:apply-templates select="//x:heading" /> 
  </xsl:template>

- <xsl:template match="x:heading">
  - <section>
  -   <title>
        <xsl:value-of select="." /> 
      </title>
      <xsl:apply-templates select="following-sibling::*" /> 
    </section>
  </xsl:template>

- <xsl:template match="text()|node()|@*">
    <xsl:copy-of select="." /> 
  </xsl:template>

The above puts me in an infinite loop.  I have no idea why.  I've tried
loads of different techniques.  The above seems to be close, but I don't
know how to stop coping nodes that don't belong in a specific section.  I'm
thinking I need to create a nodeset that contains all following siblings up
to but not including the next heading tag.  My gut tells me this should be
easy, but I've been looking at this problem long enough that I'm cross eyed.
Any help would be appreciated.


Regards,
Don Stinchfield
Red Bridge Interactive, Inc.




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


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


Current Thread